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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
KiwiPete
Frequent Visitor

Dynamic create groupings from User input selection

Hi, I have some large datasets with 100+ columns.  Different users will want to group and sum different combinations of columns.  I would like to cherry pick which columns to group from an input table template.

 

The below code snippet below would sum Field1 and Field3, picked up from the user input table.

 

The plan is to list.zip three lists, {new field nameS},    {Accumulator funcitonS}     &   {Type} as 

                 List1                      List2                           List3

{"SumField1"},   {each List.Sum([Field1])},   {type number}

{"SumField3"},   {each List.Sum([Field3])},   {type number} 

{"SumFieldX"},   {each List.Sum([FieldX])},   {type number} ...

 

The first list as from user input table.     

The type list is generated using List.Repeat to the count of the first list, 

However I can't work out how to create the second {each List.Sum([FieldX])} list with the correct sequence of field names (from list 1, 1 through X).  Everything I try either creates a string (not a function) or a static FieldX portion.  I have tried using List.Generate but strings and List.Repeat can only produce a stactic single filed name and I can't find a way to edit the X element...

 

Code snippet that works, but need to be able to dynamically create the portion

let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Key"},
{
{"SumField1", each List.Sum([Field1]), type number},
{"SumField3", each List.Sum([Field3]), type number}
})
in
#"Grouped Rows"

 

Seems to be that the editor (and the ribbon) knows to treat 'each' as a function but I can't find any incrementing List(dot) function to treat the 'each' element of a built list as a function.  any ideas apprecitated., thnx

 

 

Capture.PNG

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @KiwiPete ,

 

If you don't want to change the data structures, how about using DAX? It may be much easier.

slicer1.gif

 

If the data structure can be changed, how about using UnPivot like so:

unpivot.gif

 

 

Best Regards,

Icey

 

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

 

View solution in original post

3 REPLIES 3
KiwiPete
Frequent Visitor

That does look supper poweful, Let me go and investigate

Icey
Community Support
Community Support

Hi @KiwiPete ,

 

Does it work in your scenario?

 

 

Best Regards,

Icey

Icey
Community Support
Community Support

Hi @KiwiPete ,

 

If you don't want to change the data structures, how about using DAX? It may be much easier.

slicer1.gif

 

If the data structure can be changed, how about using UnPivot like so:

unpivot.gif

 

 

Best Regards,

Icey

 

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

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.