cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JTR
Frequent Visitor

Sum multiple Columns formula

Hello,

 

I would like to sum mutliple columns in a table. For now, I simply did it like this:

JTR_0-1636970421669.png

As the amount of columns might vary from time to time, I aim to make it more flexible. In all columns that have to be summed the word "Capacity" will always appear in the first row. Is it possible to create a Column based on a formula in the Power Query Editor which automatically sums all Columns which have the word capacity in its first row?

 

Thank you very much for your help.

 

Best regards,

Jakob

1 ACCEPTED SOLUTION
Vera_33
Super User
Super User

Hi @JTR 

 

Can you promote the first row as header or you need the column names remain as Column1, Column2...? Here is one way if you promote the first row, my previous step is Change Type, you need to modify it accordingly

 

Vera_33_0-1636985363544.png

 

Table.AddColumn(yourPreviousStep, "Custom", (x) => List.Sum(List.Transform( List.Select( Table.ColumnNames( yourPreviousStep), each Text.Contains(_,"Capacity")), each Record.Field(x,_))))

 

View solution in original post

2 REPLIES 2
Vera_33
Super User
Super User

Hi @JTR 

 

Can you promote the first row as header or you need the column names remain as Column1, Column2...? Here is one way if you promote the first row, my previous step is Change Type, you need to modify it accordingly

 

Vera_33_0-1636985363544.png

 

Table.AddColumn(yourPreviousStep, "Custom", (x) => List.Sum(List.Transform( List.Select( Table.ColumnNames( yourPreviousStep), each Text.Contains(_,"Capacity")), each Record.Field(x,_))))

 

JTR
Frequent Visitor

It works like this, thank you very much!

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors