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

New column

Hi,
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.

 

Income
Group1          where account no is 3
Group2          where account no is 2 or 3 or 5, and account group is not 20
Group3          where account group is 20
All costs         Group1 + Group2 + Group3

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

 

Income

Totalsum

Group1

1500

Group2

1000

Group3

1400

All costs

3900

 

Thanks in advance!

8 REPLIES 8
Greg_Deckler
Super User
Super User

@Anonymous Try using Grouping feature. Your total row will contain all costs.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

 Hi @Greg_Deckler 
What I want to add are rows with the logic mentioned above.
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?

@Anonymous Use a disconnected table with your group names including the All costs group. Then you can create a measure like this:

Measure = 
  VAR __Group = MAX('DisconnectedTable'[Column])
RETURN
  SWITCH(__Group),
    "Group1", CALCULATE('Table'[Income]),'Table'[AccountNo] = 3,
    ...
  )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler 

Hi, sorry if my question was unclear.
What I want is to create a calculated column, not a measure. I have measures, and I want to visualize this calculated column using my already created measures.

I want my calculated column to look like below
NewColumn
Group1
Group2
Group3
All Groups     --> (when I visualize the column with measures for this row, the measure value should show the sum of Group1 + Group2 + Group3)

I am using the expression below, but it's not giving me the expected results. 

 

NewColumn=  var g1 = account no=3 var g2 = account no in { 4, 5, 6} && account group <> 20 var g3= account group = 20 return SWITCH(TRUE(),g1,"Group1",g2,"Group2",g3,"Group3", g1 || g2 || g3, "All Groups" )

@Anonymous Your calculation seems to be weird. It is like you are trying to return two values for the same row in the same column, both "Group1" and "All Groups". You can't do that, a row in a column can only have a single value, either "Group1" or "All Groups".


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler   I have other groups that are not mentioned in my post. as Group4, Group5, Group6, and AllGroup2 -> which is the sum of Group4, Group5 and Group6 So if I use total in the visualization it will give me the sum of all groups, not the sum under every third group.

Anonymous
Not applicable

@Greg_Deckler  Thanks for your reply!

Yes, that's the problem I am having. Is there any other way to do this?

 

 

@Anonymous Not the way you are doing it, no. You could use 2 columns, one that has the Group1, Group2, etc. and the other that has like All Groups and Other Groups (or just blank). Or you could do it in the measure itself or the disconnected table trick as originally mentioned. But, no, you cannot magically insert two different values into the same row and column (cell) of a table. That would require quantum physics. 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.