+ Reply to Thread
Results 1 to 40 of 40

By Group - Subtotal

  1. #1
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    By Group - Subtotal

    Hi

    I have a dataset which loads into PowerQuery. I then group the data to give me a summary. This works fine as is, but I need to be able to subtotal it as well. Looking around it seems to be quite complicated, using formulas. Is there a simpler way to do this?

    I thought about adding in subtotals in the Excel worksheet when the query had updated, but each time it's refreshed it resets the data positioning.

    Enclosed spreadsheet. Left hand is the data as supplied via Group By. On the right is the results I need to get to.

    thanks
    Barry
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    Can you provide the original source data, please?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    If you have the 2302 version of 365, you should have the GROUPBY formula function:

    =GROUPBY(Table1[[Area]:[Core?]],Table1[Spend],SUM,,2)

  4. #4
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Hi

    Have enclosed source data, thanks.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    I tried using this but kept getting an error, which pointed to [Area]:[Core?], specifically the colon. Was telling me it expected a coma.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    Which version of 365 do you have? Is it 2302?

  7. #7
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    Using PivotTable.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by AliGW View Post
    Which version of 365 do you have? Is it 2302?
    We are using 365, all up to date (I believe) and shows as version 2401.

  9. #9
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    Using PivotTable from source data.
    Attached Files Attached Files

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    OK - if you can run update and get it up to 2402 (which is the |February release), you should be able to use this:

    =GROUPBY(C2:D102,E2:E102,SUM,,2)
    Last edited by AliGW; 02-14-2024 at 10:54 AM. Reason: Typo fixed.

  11. #11
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by josephteh View Post
    Using PivotTable.
    Pivot Table does work, in fact it's what I am using currently. However, the finished copy goes to a customer and requires to be formatted as such (colours, logos etc). This is one tab of 25, and when we copy/paste special, of course, it loses all formatting. It's fine to reformat, but trying to find a quicker, more automated solution.

  12. #12
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    You can first paste as values, then paste as formats.

  13. #13
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: By Group - Subtotal

    AliGW I am using v2401 & do not have groupby yet. As far as I know it's still only on the beta channel.

  14. #14
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by AliGW View Post
    OK - if you can run update and get it up to 2302 (which is the |February release), you should be able to use this:

    =GROUPBY(C2:D102,E2:E102,SUM,,2)
    Wouldn't version 2401 be later than 2302? Looking on the release notes, 2302 was March last year?

  15. #15
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    With what you wrote in post #11, how will any formula be of help?

  16. #16
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: By Group - Subtotal

    Another way,

    Please Login or Register  to view this content.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by josephteh View Post
    With what you wrote in post #11, how will any formula be of help?
    Unless I'm thinking this all wrong, if the Group By function, or a formula, in Power Query then updated the worksheet, once we disconnect from the Query to send to customer, all the data remains, as does the formatting (this is what we do with other reports). So in essence, Power Query is doing all the work before it refreshes the worksheet.

    Does that make sense?

  18. #18
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: By Group - Subtotal

    GROUPBY is for Insider releases

  19. #19
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    You can do the same with the file in post #9.

  20. #20
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by josephteh View Post
    You can do the same with the file in post #9.
    Sorry, I'm not explaining this all very well.

    Currently we use Pivot Tables. We are having to copy/paste value then copy/paste format on each tab. There are in excess of 25 tabs, and this report is run a lot! So for each time the report is run, we have 50+ copy/paste routines to do.

    The group function allows us to format how we like (if we could only get subtotals into it), and we don't need to copy/paste at all with it...just remove the Query link.

    Trying to get this automated as much as possible, so all we have to do is disconnect the Query and send out.

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    Quote Originally Posted by Fluff13 View Post
    AliGW I am using v2401 & do not have groupby yet. As far as I know it's still only on the beta channel.
    No - it has been released on 2402, apparently (as I said above), so you'll get it with that release. 2403 is the beta channel version at the moment.

  22. #22
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    Quote Originally Posted by barrywhitelaw View Post
    Wouldn't version 2401 be later than 2302? Looking on the release notes, 2302 was March last year?
    Sorry - that was a typo. I meant 2402, which is this month's release. 2302 was rolled out from February last year.

  23. #23
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    Have you tried to delete the source data and query?

  24. #24
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by AliGW View Post
    Sorry - that was a typo. I meant 2402, which is this month's release. 2302 was rolled out from February last year.
    Ah ok, so when I run an update check it tells me I'm up to date. On the 'View Updates' option in Excel, the latest number is 2401 February 13...so maybe it's still to land as an update. Will watch out for it.

  25. #25
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    With your requirements, you can forget about any formula solution.

  26. #26
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: By Group - Subtotal

    I'm not sure I recommend it, but it can be done in PQ - example in the attached version of your file, which will probably need tweaking for your actual datasets, so I've tried to keep the steps separate for simplicity. The M code for your sample is:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Rory

  27. #27
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: By Group - Subtotal

    You were asked (several times by Ali) to produce the source data but didn't. I have added a few more rows to simulate source data.

    Formula version, with conditional formatting to highlight subtotal and total rows. Title row was applied manually.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  28. #28
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Thank you

    FYI, source data was provided in step #4! I can still see it, can't you?

    thanks
    Barry
    Last edited by AliGW; 02-14-2024 at 12:26 PM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  29. #29
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: By Group - Subtotal

    Apols. You probably have this sorted already, but as stubbornly possessive as a dog with bone, I wanted to get this to work.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  30. #30
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Thank you. I honestly envy anyone that can look at code like this an understand anything it's doing :-D.
    I tried to apply it to my live data, but get error messages every time, so it'll me doing something wrong. Seeing it worked on the sample version, I'll keep at it and see if I can work out the issue.

    Hopefully the update for Excel will come out soon as Ali said and it'll include the workaround.

    thanks again
    Last edited by AliGW; 02-15-2024 at 06:26 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  31. #31
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: By Group - Subtotal

    Does it work in the sample I provided if you change a few of the amounts in the raw data?

    Providing the columns are the same in your real data as the amneded sample... it should work OK. I tweaked the formula so that you only have to adjust teh table name in two places (red)

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    >>>IF<<< everything else is the same... it >>should<< work automatically
    Attached Files Attached Files

  32. #32
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    This is maybe beyond my abilities at present!
    Looking at the file you sent back, to me looks like the formula is in cell B4. My data starts at A1, so selecting A1, pasting the formula in the function bar, amending the table name and clicking the tick. Nothing actually happens, and actually disappears out the formula bar. It'll be me doing something wrong I can guarantee it!

    I appreciate the work you've done here, just maybe, for now, I need to find a less automatic route!
    Last edited by AliGW; 02-15-2024 at 06:26 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  33. #33
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: By Group - Subtotal

    Reread my last post. If your data are in a Table, all you need to do is update tge table name in the formula *red) as indicated.

  34. #34
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Thanks, I did read it.

    My data is in a table called Summary.
    I am selecting cell A1 (which is where my table starts) and pasting the formula into the formula bar. Is this correct?
    I am then changing Table1 (you have in red) to Summary
    Clicking the tick. At this point the formula bar empties, and nothing happens.

    Please assume I'm an idiot. Are there any other steps I should have been doing? Don't assume I know what to do with the formula, however obvious it may be :-)

    thanks
    Last edited by AliGW; 02-15-2024 at 06:43 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

  35. #35
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    You don't paste the formula into the source table - you paste it into an empty cell where you want the results to start. Then you change the table references to point to the source table.

  36. #36
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by AliGW View Post
    You don't paste the formula into the source table - you paste it into an empty cell where you want the results to start. Then you change the table references to point to the source table.
    I knew it would be me doing something stupid! Thank you!

  37. #37
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    Quote Originally Posted by Glenn Kennedy View Post
    Reread my last post. If your data are in a Table, all you need to do is update tge table name in the formula *red) as indicated.
    Got it working, with thanks also to AliGW.

    Thanks for your help, and patience!

  38. #38
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: By Group - Subtotal

    Glad to have helped.

    If you have not already done so, remember that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

  39. #39
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,060

    Re: By Group - Subtotal

    So, you have marked the thread as "Solved". Appreciate if you could share with us how you tackle your requirements in post #20. Thank you.

  40. #40
    Registered User
    Join Date
    02-02-2024
    Location
    Glasgow, Scotland
    MS-Off Ver
    365
    Posts
    36

    Re: By Group - Subtotal

    A table was created in Power Query Editor and closed into a worksheet. Then using Glenn's code from post #29 and with help from AliGW in post #35, pasted the formula into an empty cell where I wanted the result to show. Amended the 2 Table1 refs in the coding to match my table name, and worked perfectly.
    Last edited by AliGW; 02-15-2024 at 07:52 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Subtotal only group duplicates if value in column
    By Chickenbones in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-19-2021, 11:28 AM
  2. Group by Data and to do Subtotal.
    By ashrafk07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2017, 01:12 AM
  3. Group+Subtotal HOW?
    By toci in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-23-2015, 02:18 PM
  4. [SOLVED] Subtotal including first Row of next group
    By yossel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-09-2014, 05:18 PM
  5. Replies: 1
    Last Post: 10-19-2012, 07:55 AM
  6. How to Insert Group in Subtotal
    By koolguys4u in forum Excel General
    Replies: 1
    Last Post: 03-25-2012, 12:10 PM
  7. [SOLVED] Group / Outline / subtotal
    By tikchye_oldLearner57 in forum Excel General
    Replies: 0
    Last Post: 06-22-2006, 06:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1