• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

RunningTotals for Sub-category without using Function|Power Query|Excel Forum|My Online Training Hub

You are here: Home / RunningTotals for Sub-category without using Function|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryRunningTotals for Sub-category with…
sp_PrintTopic sp_TopicIcon
RunningTotals for Sub-category without using Function
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
1
September 10, 2020 - 8:01 pm
sp_Permalink sp_Print

Hi PQ Guru

I had tried using function to involve to get running totals for Fields1,  and was wondering whether can you group by field get Index for each field 1 value,  then groupby again to insert Running total in  (see the following code in attachment),  but get error

 

For all advise,  please

 

let
Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Field 1", type text}, {"QTY", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Field 1", Order.Ascending}, {"QTY", Order.Ascending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"Field 1"}, {{"MyData", each _, type table [Field 1=nullable text, QTY=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([MyData],"Index",1,1,Int64.Type)),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MyData"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"QTY", "Index"}, {"QTY", "Index"}),
#"Grouped Rows1" = Table.Group(#"Expanded Custom", {"Field 1"}, {{"Grouped", each _, type table [Field 1=nullable text, QTY=number, Index=number]}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows1", "Custom1", each Table.AddColumn([Grouped],"RTotal",List.Sum(List.Range(#"Grouped Rows1"[QTY],0,[Index]))))
in
#"Added Custom1"

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1510
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
September 10, 2020 - 9:02 pm
sp_Permalink sp_Print

Hi Chris,

That query is throwing an error because you don't have a Column named QTY but I think that may be beside the point.

You've only got 2 columns in your source so once you have grouped by Field 1 you haven't got any other columns to group by. 

What is the result you are hoping to get?  Can you please provide an example.

Regards

Phil

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
3
September 10, 2020 - 9:04 pm
sp_Permalink sp_Print

Hi Philip,

I used function produce the following output

Field 1 QTY GrpByRunningTotal
D001 2 2
D001 4 6
D001 89 95
D002 4 4
D002 54 58
T003 6 6
T003 11 17
T003 67 84
Z001 61 61
Z002 12 12
Z003 6 6
Z004 2 2
Z004 5 7
Z004 6 13
Z005 4 4
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1510
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
September 10, 2020 - 9:07 pm
sp_Permalink sp_Print

Hi Chris,

Yes I saw that in the workbook so if that is what you want as a result, I don't understand what you are asking for help with as you've already done it?

Regards

Phil

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
5
September 10, 2020 - 9:18 pm
sp_Permalink sp_Print

Hi Philip,

I am just exploring without using function method is it possible,   that is the last custom column if I can insert the running total into  2nd grouping  (with Index inserted in the first grouping),  so I am seeking advise from you guys whether can be done,  or definitely need to use function

 

Thank you !

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1510
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
September 10, 2020 - 9:30 pm
sp_Permalink sp_Print

Hi Chris,

I'd use a custom function to create a running total.

But that aside, your question was actually can you group by field get Index for each field 1 value,  then groupby again to insert Running total. 

If you've grouped Field 1 then what column are you going to group by again?  An Index column will just have numbers 1,2,3 etc so can't be grouped.  And with Field 1 grouped you can't insert a running total column, it'll just be a grand total for each group in Field 1.

If I am missing something then you need to supply an example of what you want as a result.  The table in post #3 above does not show any groupings.

Phil

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
7
September 10, 2020 - 10:35 pm
sp_Permalink sp_Print

Hi Philip

Thanks for your response and explanation

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Ben Hughes, Alison West, Ramon Lagos, Shawn Barwick, Chris Pinto
Guest(s) 12
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
yashal minahil
Oluwadamilola Ogun
Yannik H
dectator mang
Francis Drouillard
Orlando Inocente
Jovitha Clemence
Maloxat Axmatovna
Ricardo Freitas
Marko Meglic
Forum Stats:
Groups: 3
Forums: 24
Topics: 6201
Posts: 27185

 

Member Stats:
Guest Posters: 49
Members: 31861
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.