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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Anonymous
Not applicable

Sum a column if another column has repeating values

Hello,

I have a table that follows this structure:

Code   Level   Total   
 111 A 1
 111 A 1
 222 B 1
 333 B 2
 333 B 1
 111 C 1
 222 D 1
 444 D 2

 

As you can see, the same "Level" can have more than one distinct "Code".

I want to create a measure that sums the "Total" column only if the "Level" is repeated for more than one distinct "Code".

So I wanted a way to know the sum of the "Total" column for each "Level" that is repeated in distinct Codes.


Based on the table above, this measure would bring me the following sum for each Level:

A = 0 

B = 4

C = 0

D = 3

1 ACCEPTED SOLUTION
andhiii079845
Solution Sage
Solution Sage

Try this:

 

MeasureTotal = 

VAR __table = SUMMARIZE(Table2,Table2[Code],Table2[Level],"count",DISTINCTCOUNT(Table2[Code]),"sum",sum(Table2[Total]))
VAR _table2 = SUMMARIZE(__table,Table2[Level],"countCode",sumx(__table,[count]),"sumtotal",sumx(__table,[sum]))
RETURN IF(sumx(_table2,[countCode])>1,sumx(_table2,[sumtotal]),0)
andhiii079845_0-1677614379433.png

 

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
andhiii079845
Solution Sage
Solution Sage

Try this:

 

MeasureTotal = 

VAR __table = SUMMARIZE(Table2,Table2[Code],Table2[Level],"count",DISTINCTCOUNT(Table2[Code]),"sum",sum(Table2[Total]))
VAR _table2 = SUMMARIZE(__table,Table2[Level],"countCode",sumx(__table,[count]),"sumtotal",sumx(__table,[sum]))
RETURN IF(sumx(_table2,[countCode])>1,sumx(_table2,[sumtotal]),0)
andhiii079845_0-1677614379433.png

 

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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