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
aszpic
Frequent Visitor

Sum values only one time

Hello everyone,

 

I have a table with 2 columns: 'Code' and 'Values'. The Code can be repeated.

The Values column is the same for each code, so 2 Values for 'CodeA' are equal to each other, and 2 values for 'CodeB' are also the same.

What I need is a measure to sum ONE TIME each value for each code, so in the example of the table below I would only need to sum 1 value for CodeA and 1 value for CodeB and the value for CodeC (3+5+7)

 

I thought a way that is using an auxiliar column named 'Unique' which is '1' if it is the first time the Code appears, and '0' if not, and use a CALCULATE function later. But I couldn't find a way to make this 'Unique' columns.

 

The Unique column would be:

Code     Value   Unique

CodeA   3         1

CodeA   3         0

CodeB   5         1

CodeB   5         0

CodeC   7         1

 

Thanks in advance!

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

@aszpic

 

Here's the MEASURE that will do this for you...

 

Measure =
DIVIDE (
    SUM ( 'Table'[Value] ),
    CALCULATE ( COUNTA ( 'Table'[Code] ), ALLEXCEPT ( 'Table', 'Table'[Code] ) ),
    0
)

 

Sum Values only 1 per Code.png

 

Good Luck! Smiley Happy

View solution in original post

2 REPLIES 2
Sean
Community Champion
Community Champion

@aszpic

 

Here's the MEASURE that will do this for you...

 

Measure =
DIVIDE (
    SUM ( 'Table'[Value] ),
    CALCULATE ( COUNTA ( 'Table'[Code] ), ALLEXCEPT ( 'Table', 'Table'[Code] ) ),
    0
)

 

Sum Values only 1 per Code.png

 

Good Luck! Smiley Happy

aszpic
Frequent Visitor

It will take me a while to understand why this works, but it works. Thank you!

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.