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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

How to sum over a ever changing list of column names

Hi everyone. Please give me some help.

Let's say I have a Table: [table]

I'd like to add a column whose value is the sum over all this table's columns except for column A and B. 

The column names changes every time the table is loaded from its source except for column A and B.

What I am doing now is:

qlist = Table.ColumnNames([table]),
openCAPAlist = List.RemoveItems(qlist, {"A","B"}),
#"Added Custom" = Table.AddColumn([table], "#added column", each List.Sum(Record.ToList(Record.SelectFields(_, openCAPAlist)))),

 

This works. However when openCAPAlist is big, it takes too long to execute somehow, which is strange given the table has only 19 columns and 74 rows.

Is there any better way to do it?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I solved it by using List.Sum(Record.FieldValues(Record.SelectFields(_, List.Difference()))). 

Thanks.

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Just thinking aloud - how about selecting the 2 columns (A and B), right clicking and "unpivoting other columns".  Now we can write a DAX measure in the visual to get your desired result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish, appreciate your reply. I am looking to save the summation into a new columns in the [table]. So Is there a way to do what you said in Query M? Also if so, Can you going into a bit detail about how to go from the unpivoted table to the sum of the rest of the columns? To my understanding, after unpivot, I will be left expanded column A and column B and an extra column with all other column names as this new column's entries' value.

 

Hi,

Could you share some data and show the expected result?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

I solved it by using List.Sum(Record.FieldValues(Record.SelectFields(_, List.Difference()))). 

Thanks.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors