Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Aggregation - "Group by" with dynamic column parameters

Hi!
I have Table A, B and C. Table A is table with source data. I would like to obtain a table where I see only columns that are written in Table B and to aggregate data from columns that are written in Table C.

hmolan_0-1594634253921.png

hmolan_1-1594634284534.png

I can't create in any way function List.Sum() with dynamic parameter -> so that when there are 2 names of columns in Table C, then it will aggregate both of them (when 3, 3 of them etc.) -> it results in error.
The case is simplified here, but I need it dynamic as there might be e.g. 20 columns with data and I would like to select which one of them should be used during THIS aggregation.

 

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="TableA"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Heading A", type text}, {"Heading B", Int64.Type}, {"Heading C", type text}, {"Heading D", type text}, {"Heading E", Int64.Type}, {"Heading F", type text}}),
    Custom1 = List.Combine ( {ColToBePresented, ColToBeAggregated}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",Custom1),
    Function1 = (x) => each List.Sum([x]),
    #"Converted to Table" = Table.FromList(ColToBeAggregated, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Invoked Custom Function" = Table.AddColumn(#"Converted to Table", "Query2", each Function1([Column1])),
    #"Added Custom" = Table.AddColumn(#"Invoked Custom Function", "Custom", each type number),
    Custom2 = Table.ToRows(#"Added Custom"),
    Custom3 = Table.Group(#"Changed Type", ColToBePresented, Custom2)
in
    Custom3

 

 

This is what I would like to achieve (done with pivotTable, which is not an option in my case):

hmolan_0-1594634735579.png

 

Can You Help me? Is it possible to do it?

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Would you please refer to the similar post: https://community.powerbi.com/t5/Power-Query/Power-Query-Aggregate-Columns-with-Dynamic-Column-Names/td-p/803594?

 

If it dosen't help, perhaps @ImkeF  or @edhans have some ideas.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

1 REPLY 1
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Would you please refer to the similar post: https://community.powerbi.com/t5/Power-Query/Power-Query-Aggregate-Columns-with-Dynamic-Column-Names/td-p/803594?

 

If it dosen't help, perhaps @ImkeF  or @edhans have some ideas.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.