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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.