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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
JustDavid
Helper IV
Helper IV

Table.Group Dynamically Columns

Power Query Gurus,

 

I have a step below where I'm grouping all columns that has 'Column#' where # is a number from 2 onwards.

 

 

 

= Table.Group(Custom1, {"#"Remove Top Rows"}, 
{
  {"Column2", each List.Sum([Column2]), type number}, 
  {"Column3", each List.Sum([Column3]), type number}, 
  {"Column4", each List.Sum([Column4]), type number}, 
  {"Column5", each List.Sum([Column5]), type number}, 
  {"Column6", each List.Sum([Column6]), type number}, 
  {"Column7", each List.Sum([Column7]), type number}, 
  {"Column8", each List.Sum([Column8]), type number}, 
  {"Column9", each List.Sum([Column9]), type number}, 
  {"Column10", each List.Sum([Column10]), type number}
}
)

 

 

 

My question is how do I make them dynamic, so that in a sense, if tomorrow instead of Column2 to Column10 becomes Column2 to Column5  or  Column2 to Column 15, it can automatically assign it so that the M code doesn't breaks.

 

Edit: Able to resolve by google and answer is also in this forum.

 

Power Query Group by aggregation with dynamic column names 

 

 

 

Modified the code to my own fit

 

Table.Group(#"PreviousStep", {"Custom"}, 
   List.Transform(
      List.Difference(Table.ColumnNames(#"PreviousStep"), {"Custom"}), 
      (l)=> {l, each List.Sum(Table.Column(_, l)), type number}
   )
)

Thanks

1 ACCEPTED SOLUTION
JustDavid
Helper IV
Helper IV

Per Dino Tao's recommendation so as to mark this thread as solved.

 

Table.Group(#"PreviousStep", {"Custom"}, 
   List.Transform(
      List.Difference(Table.ColumnNames(#"PreviousStep"), {"Custom"}), 
      (l)=> {l, each List.Sum(Table.Column(_, l)), type number}
   )
)

 

View solution in original post

2 REPLIES 2
JustDavid
Helper IV
Helper IV

Per Dino Tao's recommendation so as to mark this thread as solved.

 

Table.Group(#"PreviousStep", {"Custom"}, 
   List.Transform(
      List.Difference(Table.ColumnNames(#"PreviousStep"), {"Custom"}), 
      (l)=> {l, each List.Sum(Table.Column(_, l)), type number}
   )
)

 

Anonymous
Not applicable

Hi @JustDavid ,

I'm glad you found a solution!
I suggest you revert with a new reply below with your answer and mark it as a solution, as posts that have been solved will be easier for other users to find, and perhaps you can help more users who are facing the same problem, thank you!

Best Regards,
Dino Tao

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.