简体   繁体   中英

Dax add a calculated column

I have a table with different measures and columns, including columns account number, account group, and a measure called Totalsum. I want to add a column called Income with the following 4-row names.

在此处输入图片说明

so when I add the column Income and the measure Totalsum on the table visual, It should look like below

在此处输入图片说明

I used the following expression to create the column Income with the rows names Group1, Group2, and Group3, but I don't know how to get the row name All costs( it's the sum of the other three rows)

Income:= var g1 = account no=3 var g2 = account no= 2 || account no= 3 || account no = 5 && account group <> 20 var g3= account group = 20 return SWITCH(TRUE(),g1,"Group1",g2,"Group2",g3,"Group3")

So How can I add the row name All costs in the above expression?

I don't see a point in creating an extra condition for "All Cost" when Table Visualization can do it for you with the "Total" label enabled (which you can rename as "All Cost". See the Picture below:

See Picture

Also, for "nicer" code, you can use "IN" function instead of multiple "||":

var g2 = account no IN {2, 3, 5} && account group <> 20 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM