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.
Hello,
How do I create a measure that sums values for distinct Ids only?
For example, in the table below I want to the sum values for just the distinct IDs so the answer should be 5+6+8+10 = 29
Thanks.
IDs | Value |
1 | 5 |
1 | 5 |
2 | 6 |
3 | 8 |
4 | 10 |
4 | 10 |
Solved! Go to Solution.
@speedramps , thanks for the tip about SUMMARIZE being CPU intensive. To re-write the measure without it would be like this:
DistinctValueSum =
SUMX(
DISTINCT(
SELECTCOLUMS(
'YourTable'
,"_IDs", 'YourTable'[IDs]
,"_Value", 'YourTable'[Value]
)
)
,[_Value]
)
Happy to help. Whichever answer worked for you, please mark as the solution so that other forum members can benefit as well when searching for solutions.
Sorry my bad, I didnt read the question.
Just change my previous instructions to the following.
Hi,
I'd use
MyMeasure =
SUMX( DISTINCT( MyTable ), MyTable[Value] )
though not sure I've understood correctly.
Hi Jo's
Thanks for trying to help but it wont give the correct answer. Try it and then read and try my solution. Many thanks for trying !!!
What happen if values are not same in same ID?
IF we want to average:
Sumx(values([IDs], calculate(average([Value]))
IF we want to get the max:
Sumx(values([IDs], calculate(max([Value]))
Try this ....
Create 2 measures ......
Thanks for reaching out for help.
I have helped you, now please help me by giving kudos.
Remeber we are unpaid volunteers.
Click the thumbs up and accept as solution button.
One question per ticket please. If you need to extend your request then please raise a new ticket.
You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you !
@speedramps But what happens if different IDs have the same value like ID 1 and ID 4 in the table below - In the case below the answer should be 34 and so your method will not work as it needs to also consider the IDs.
IDs | Value |
1 | 10 |
1 | 10 |
2 | 6 |
3 | 8 |
4 | 10 |
4 | 10 |
@JRA21_13_19_25 , this measure should work:
DistinctValueSum =
SUMX(
SUMMARIZE(
'YourTable'
,'YourTable'[IDs]
,'YourTable'[Value]
)
,'YourTable'[Value]
)
Is it possible in your source data to have different values for Value for the same IDs? e.g.
IDs | Value |
1 | 5 |
1 | 6 |
If so, what should the result be in this case? Or will that never happen in the data?
Well done EylesIT. That will work but a SUMMARIZE inside in SUMX is unnecessary CPU effort.
Thanks for helping but this should calc the answer quicker on larger datasets ...
@speedramps , thanks for the tip about SUMMARIZE being CPU intensive. To re-write the measure without it would be like this:
DistinctValueSum =
SUMX(
DISTINCT(
SELECTCOLUMS(
'YourTable'
,"_IDs", 'YourTable'[IDs]
,"_Value", 'YourTable'[Value]
)
)
,[_Value]
)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
26 | |
19 | |
14 | |
10 |
User | Count |
---|---|
58 | |
50 | |
44 | |
19 | |
19 |