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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ScottA
Frequent Visitor

Calculating totals based on data subsets

Hi All,

 

I have versioned roster data, and I get this by employee. E.g. Everyones roster is published (at differing times) and the data flows through. If a change is then made to someones roster, I get their whole roster of data again with the change. The changes are timestamped (and versioned as a quick reference). Basic example below.

 

Employee NumberFirst NameSurnameRoster GroupResource GroupBaseDateActivityLayover LocationRosterRoster VersionOccurred When
001BobJonesTestUnder TrainingAKL20/03/2020WORK 2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL20/03/2020LAYOVERBHE2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL21/03/2020WORK 2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL22/03/2020OFF 2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL20/03/2020WORK 2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL20/03/2020LAYOVERWLG2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL21/03/2020WORK 2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL21/03/2020LAYOVERCHC2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL22/03/2020WORK 2020.03220/03/2020 18:57
002JohnSmithTestUnder TrainingWLG20/03/2020OFF 2020.03114/03/2020 13:13
002JohnSmithTestUnder TrainingWLG21/03/2020OFF 2020.03114/03/2020 13:13
002JohnSmithTestUnder TrainingWLG21/03/2020OFF 2020.03114/03/2020 13:13
002JohnSmithTestUnder TrainingWLG20/03/2020OFF 2020.03214/03/2020 14:26
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03214/03/2020 14:26
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03214/03/2020 14:26
002JohnSmithTestUnder TrainingWLG20/03/2020WORK 2020.03314/03/2020 17:40
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03314/03/2020 17:40
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03314/03/2020 17:40

 

So at any given time, employee 1 might be up to version 4 but employee 2’s latest roster is still their first roster version because there are no changes. My ultimate vision is to step through these change timestamps and show change as time progresses which I’ll do with the play axis or similar.

 

At each timestamp I want to get each employees latest roster version, and then make calculations on each employees latest roster to arrive at a roster total. For example total hotel nights.

 

In the screenshots below, each row of the table is correct (I guess only because I’m displaying the table by employee), but the total is wrong because at the shown timestamp employee 2 has the biggest roster version and they have no hotel nights.

 

How do I get the measure to evaluate for each employee as I step through timestamps?

 

Appreciate all help and advice

 

image.png

 

 

 

 

 

 

 

 

*Latest Roster Version = CALCULATE(MAX('Roster Data'[Roster Version]),FILTER('Roster Data','Roster Data'[Occurred When]<=SELECTEDVALUE('Change Timestamp Summary'[Occurred When])))
*Hotel Nights = 
VAR LatestRosterVersion = [*Latest Roster Version]
RETURN
CALCULATE(COUNTROWS('Roster Data'),'Roster Data'[Layover Location]<>"",'Roster Data'[Roster Version]=LatestRosterVersion)

 

 image.png

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

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:

 

10.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
ScottA
Frequent Visitor

Hi All,

 

I have versioned roster data, and I get this by employee. E.g. Everyones roster is published (at differing times) and the data flows through. If a change is then made to someones roster, I get their whole roster of data again with the change. The changes are timestamped (and versioned as a quick reference). Basic example below.

 

Employee NumberFirst NameSurnameRoster GroupResource GroupBaseDateActivityLayover LocationRosterRoster VersionOccurred When
001BobJonesTestUnder TrainingAKL20/03/2020WORK 2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL20/03/2020LAYOVERBHE2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL21/03/2020WORK 2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL22/03/2020OFF 2020.03114/03/2020 13:11
001BobJonesTestUnder TrainingAKL20/03/2020WORK 2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL20/03/2020LAYOVERWLG2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL21/03/2020WORK 2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL21/03/2020LAYOVERCHC2020.03220/03/2020 18:57
001BobJonesTestUnder TrainingAKL22/03/2020WORK 2020.03220/03/2020 18:57
002JohnSmithTestUnder TrainingWLG20/03/2020OFF 2020.03114/03/2020 13:13
002JohnSmithTestUnder TrainingWLG21/03/2020OFF 2020.03114/03/2020 13:13
002JohnSmithTestUnder TrainingWLG21/03/2020OFF 2020.03114/03/2020 13:13
002JohnSmithTestUnder TrainingWLG20/03/2020OFF 2020.03214/03/2020 14:26
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03214/03/2020 14:26
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03214/03/2020 14:26
002JohnSmithTestUnder TrainingWLG20/03/2020WORK 2020.03314/03/2020 17:40
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03314/03/2020 17:40
002JohnSmithTestUnder TrainingWLG21/03/2020WORK 2020.03314/03/2020 17:40

So at any given time, employee 1 might be up to version 4 but employee 2’s latest roster is still their first roster version because there are no changes. My ultimate vision is to step through these change timestamps and show change as time progresses which I’ll do with the play axis or similar.

 

At each timestamp I want to get each employees latest roster version, and then make calculations on each employees latest roster to arrive at a roster total. For example total hotel nights.

 

In the screenshots below, each row of the table is correct (I guess only because I’m displaying the measure by employee in the table), but the total is wrong because at the shown timestamp employee 2 has the biggest roster version and they have no hotel nights.

 

How do I get the measure to evaluate for each employee as I step through timestamps?

 

Appreciate all help and advice

image.png

 
 

 

 

 

 

 

 

 

*Latest Roster Version = CALCULATE(MAX('Roster Data'[Roster Version]),FILTER('Roster Data','Roster Data'[Occurred When]<=SELECTEDVALUE('Change Timestamp Summary'[Occurred When])))
*Hotel Nights = 
VAR LatestRosterVersion = [*Latest Roster Version]
RETURN
CALCULATE(COUNTROWS('Roster Data'),'Roster Data'[Layover Location]<>"",'Roster Data'[Roster Version]=LatestRosterVersion)

 

 

 

image.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

v-lid-msft
Community Support
Community Support

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:

 

10.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.