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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rkaushik
Frequent Visitor

Sum of Revenue for values which exist in multiple columns

Hello all,

I am trying to calulate revenue for users which exist in multiple columns as indicated in the image below. For example, for user "Paul Wright" what I am trying to calculate is that the total should be sum of first 2 rows and sum of last 2 rows because he exists in first 2 rows in column 1 and last 2 rows in column 2.

 

rev goal.PNG

 

How can I creat a calculation which is able to do this? Any help would be really appreciated. Thanks in advance

1 ACCEPTED SOLUTION

@rkaushik OK, I did this 2 different ways in the PBIX attached below signature. First, I created a disconnected Users table using this formula:

Users = DISTINCT(FILTER(UNION(DISTINCT('Table'[User1]),DISTINCT('Table'[User2]),DISTINCT('Table'[User3])),[User1]<>BLANK()))

And this measure:

Measure = 
    VAR __User = MAX('Users'[User1])
    VAR __Table = FILTER('Table', [User1] = __User || [User2] = __User || [User3] = __User)
RETURN
    SUMX(__Table,[Revenue])

I also created a version of the table where I unpivoted the user columns and then you don't even need a measure, just a simple sum:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgszVEIL8pMzyhR0lFSgGIjAwMDpVgddGmnzJwchAqwgqD84pzKPKCAS2JZZgpCjQWGAqxGmeFXBbLJ0BSkJhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User1 = _t, User2 = _t, User3 = _t, Revenue = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"User1", type text}, {"User2", type text}, {"User3", type text}, {"Revenue", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Revenue"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] <> " "))
in
    #"Filtered Rows"


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
Greg_Deckler
Community Champion
Community Champion

@rkaushik Would probably be best to unpivot your data, but you could create a measure like this:

Measure =
  VAR __User = MAX('Table'[User])
  VAR __Table = FILTER('Table',[User] = __User || [User1] = __User || [User3] = __User)
RETURN
  SUMX(__Table,[Revenue])


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , thanks for your solution.

I tried implementing it but the total for each user hasn't changed. It is still displaying the numbers as it was previously. 

What I am trying to create is a table where I can show each user and their respective total. 
Also, just wanted to confirm if [user] = column 1, [user1] = column2 and [user3]  = column3?

@rkaushik I used [user], [user1] and [user2] as the column names. Since you didn't provide them, I made them up. Post sample data as text, including the column header names and I'll get you a working file/calculation.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Got it.

Here's a sample data that I'm working with: 

User1User2User3Revenue
Paul Wright  2000
Paul WrightBill 200
RoslynDavidBill8200
RoslynPaul WrightBill600
RoslynPaul Wright 1500

 

I am trying to create a table that could showcase this:

UserRevenue
Paul Wright4300
Roslyn10300
David8200
Bill9000

 

Let me know if I can provide more information. Thanks again for your help.

@rkaushik OK, I did this 2 different ways in the PBIX attached below signature. First, I created a disconnected Users table using this formula:

Users = DISTINCT(FILTER(UNION(DISTINCT('Table'[User1]),DISTINCT('Table'[User2]),DISTINCT('Table'[User3])),[User1]<>BLANK()))

And this measure:

Measure = 
    VAR __User = MAX('Users'[User1])
    VAR __Table = FILTER('Table', [User1] = __User || [User2] = __User || [User3] = __User)
RETURN
    SUMX(__Table,[Revenue])

I also created a version of the table where I unpivoted the user columns and then you don't even need a measure, just a simple sum:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgszVEIL8pMzyhR0lFSgGIjAwMDpVgddGmnzJwchAqwgqD84pzKPKCAS2JZZgpCjQWGAqxGmeFXBbLJ0BSkJhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User1 = _t, User2 = _t, User3 = _t, Revenue = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"User1", type text}, {"User2", type text}, {"User3", type text}, {"Revenue", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Revenue"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] <> " "))
in
    #"Filtered Rows"


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler While the first solution you suggested didn't work, the unpivot solution worked perfectly. Thanks for your help. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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