Forum Discussion
Calculating totals based on data subsets
- 6 years ago
Hi ScottA ,
We can use the following measure by using SUMX function to meet your requirement.
*Hotel Nights = SUMX ( VALUES('Roster Data'[Employee Number]), VAR LatestRosterVersion = [*Latest Roster Version] RETURN CALCULATE ( COUNTROWS ( 'Roster Data' ), 'Roster Data'[Layover Location] <> "", 'Roster Data'[Roster Version] = LatestRosterVersion ) )
And here is the result:If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Hi ScottA ,
We can use the following measure by using SUMX function to meet your requirement.
*Hotel Nights =
SUMX (
VALUES('Roster Data'[Employee Number]),
VAR LatestRosterVersion = [*Latest Roster Version]
RETURN
CALCULATE (
COUNTROWS ( 'Roster Data' ),
'Roster Data'[Layover Location] <> "",
'Roster Data'[Roster Version] = LatestRosterVersion
)
)
And here is the result:
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Hi v-lid-msft
This is perfect, thank you. I can see how VALUES() is creating a distinct list/table of employee_numbers, and then SUMX is allowing the original measure to SUM for each row of that table.
I had been experimenting with SUMX but I just couldn't visualise how to get it to work.
Really appreciate it, cheers