The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi Everyone,
I'm trying to write a DAX measurement query to get a scalar numeric value of sum of grouped item's column based on max condition with another column.
I have the following table:
For that table, I wanna get sum of 'value' corresponding to max 'order' column for each 'node'.
For example, for 'node' n1 the largest 'order' is 45 and it's corresponding 'value' is 5.
For 'node' n2 it's 46 and corresponding 8.
And the same for third 'node'.
So in a result I wanna calculate the sum of 5, 8 and 9 and get 22.
I'm thinking about the algorithm of doing that:
1. Group by node
2. Get max order for each group
3. Get corresponding value to it.
4. Sum corresponding values.
I tried to write similar algorithm in DAX:
sumValues = COUNTAX(SUMMARIZE('table', 'table'[node], "maxGroup", MAX('table'[order])), [maxGroup])
but it's not working as expected.
I will greatly appreciate any help and thanks in advance.
Thanks,
Oleh
Solved! Go to Solution.
Hi @drru97 ,
We can use following measures to meet your requirement:
Measure =
SUMX (
DISTINCT ( 'Table'[node] ),
VAR o =
CALCULATE ( MAX ( 'Table'[order] ) )
RETURN
CALCULATE ( SUM ( 'Table'[value] ), 'Table'[order] = o )
)
Or
Measure 2 =
CALCULATE (
SUM ( 'Table'[value] ),
FILTER (
'Table',
VAR n = [node] RETURN 'Table'[order]
= CALCULATE ( MAX ( 'Table'[order] ), 'Table', 'Table'[node] = n )
)
)
By the way, PBIX file as attached.
Best regards,
Hi @drru97 ,
We can use following measures to meet your requirement:
Measure =
SUMX (
DISTINCT ( 'Table'[node] ),
VAR o =
CALCULATE ( MAX ( 'Table'[order] ) )
RETURN
CALCULATE ( SUM ( 'Table'[value] ), 'Table'[order] = o )
)
Or
Measure 2 =
CALCULATE (
SUM ( 'Table'[value] ),
FILTER (
'Table',
VAR n = [node] RETURN 'Table'[order]
= CALCULATE ( MAX ( 'Table'[order] ), 'Table', 'Table'[node] = n )
)
)
By the way, PBIX file as attached.
Best regards,
Hi @drru97 ,
This measure should help you: