+ Reply to Thread
Results 1 to 6 of 6

Power Query Sum within grouped data

  1. #1
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    615

    Power Query Sum within grouped data

    Hello,
    Work book attached with examples.

    I'm trying to sum figures in grouped data for each group, so I have the groped data ;


    Please Login or Register  to view this content.

    and I wan to sum a 'sales' column within the group, so if I were adding an index to to each grouping i'd put this after each ;

    Please Login or Register  to view this content.
    So I'd like to use list.sum in a similar way, but can't get it to work,

    each _ List.Sum( [Sales] ) }} ) , List.Sum( _ [Sales] ) etc. don't seem to work.


    i've exapneded one group and done the calculation on that group as I thought I might be able to make it a function, but couldn't get it right;

    Please Login or Register  to view this content.
    So I've like to get what i have for a single group, above, for each of the All Rows grouping,

    Richard.
    Attached Files Attached Files

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Power Query Sum within grouped data

    Pure guess

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Cttest"]}[Content],
        
    Group Table.Group(Source,"Day",{{"Sale",each List.Sum([Sales])},{"Sales%"each List.Sum([Sales])/List.Sum(Source[Sales]) }},0,(b,e)=>Number.From(Text.Length(e)>2))
    in
        Group 

  3. #3
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    615

    Re: Power Query Sum within grouped data

    Thanks,
    I'll have to work on this a bit,

    Richard.

  4. #4
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    615

    Re: Power Query Sum within grouped data

    Quote Originally Posted by Bo_Ry View Post
    Pure guess

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Cttest"]}[Content],
        
    Group Table.Group(Source,"Day",{{"Sale",each List.Sum([Sales])},{"Sales%"each List.Sum([Sales])/List.Sum(Source[Sales]) }},0,(b,e)=>Number.From(Text.Length(e)>2))
    in
        Group 
    I'm not sure what the function is doing? (b,e)=> , The prior grouping is sort of what I had , giving a percent of Groupe sales to overall,
    What I was trying to do was get a percentage, of each sale % within the group so AM / (AM +PM) and PM / (AM +PM) and so on for each days grouping.

    Richard

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Power Query Sum within grouped data

    Maybe

    PHP Code: 
    let
        Source 
    Excel.CurrentWorkbook(){[Name="Cttest"]}[Content],
        
    Group Table.Combine(Table.Group(Source,"Day",{{"T",each Table.AddColumn(_"%", (t)=>  t[Sales]/List.Sum([Sales])) }},0,(b,e)=>Number.From(Text.Length(e)>2))[T])
    in
        Group 

    Read Table.Group here

    https://www.thebiccountant.com/2018/...d-power-query/

  6. #6
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    615

    Re: Power Query Sum within grouped data

    Thanks for the link,

    Richard.

+ 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. Power Query - Feeding dynamic sheet name to Power query
    By egoosen3 in forum Excel General
    Replies: 5
    Last Post: 09-13-2023, 07:41 AM
  2. [SOLVED] Power query return total value of grouped columns
    By Dicken in forum Office 365
    Replies: 2
    Last Post: 06-20-2022, 05:30 AM
  3. Power Query Grouped Running Total
    By sle7en in forum Excel General
    Replies: 2
    Last Post: 02-13-2021, 06:30 PM
  4. [SOLVED] How to access data via VBA from a Connection Only Power Query query.
    By MLAN_75 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2020, 11:45 AM
  5. Replies: 4
    Last Post: 02-17-2020, 06:03 AM
  6. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM
  7. Replies: 2
    Last Post: 04-12-2018, 01:34 PM

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