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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

All Columns?

I have a table with several columns in it. For example: A,B,C,D,E,F,G,... The number of columns will vary.

I need to create a customer column where the new column is equal to A-(B+C+D+E+F+G...) Basically, I need to sum all the columns and then subtract column A.

 

Can someone help me with how to do this as a custom coolumn and as a measure?

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

My suggestion would be to unpivot the B,C,D,... columns by using Unpivot OTHER columns in Power Query.

 

So click Transform Data to open power query, add an Index Column if you don't have one already.

 

Select column A and all attribute columns, then Unpivot Other Columns

 

Close & Apply. Then create a matrix visual with [Index] in Rows, and create a new Measure:

Measure = SUM(table[columnA]) - SUM(table[value])

 

and put the Measure in values of the matrix.

 

There are other variations, but this should hopefully inspire you to get a solution that works. Come back with any questions.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

4 REPLIES 4
AllisonKennedy
Super User
Super User

My suggestion would be to unpivot the B,C,D,... columns by using Unpivot OTHER columns in Power Query.

 

So click Transform Data to open power query, add an Index Column if you don't have one already.

 

Select column A and all attribute columns, then Unpivot Other Columns

 

Close & Apply. Then create a matrix visual with [Index] in Rows, and create a new Measure:

Measure = SUM(table[columnA]) - SUM(table[value])

 

and put the Measure in values of the matrix.

 

There are other variations, but this should hopefully inspire you to get a solution that works. Come back with any questions.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy , thank you for your help so far. When I unpivot the data do I include the index in the columsn I select before I unpivot?

 

Also, I was really hoping to store this ne calculated value in the table and not just display it on the reports. I thought I could do this using a measure. Is this right? Or do I need to do something in the query editor in M code?

Hi @Anonymous ,

I created a sample pbix file with different methods, please check whether they are what you want. If no, please provide some sample data(exclude sensitive data) and your expected result with examples. Thank you.

all columns.png

Any comment or problem, please feel free to let me know.

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

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

@Anonymous 

Yes, select the Index column as one of the attribute columns. 

 

I suppose it is technically possible to create a DAX calculated column that will store the calculation in the table. Measures are not stored in the table though, but rather use the context of the visualizations you create in the report. Why are you wanting this though? It will not impact the raw data source. 

Power BI Order of Operations 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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