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

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.

Reply
Anonymous
Not applicable

Getting Rolling Sum From another DAX Measure

I want to get a 12-month rolling sum of my headcount. So far I have managed to get the headcount per month, but I need to get the 12-month rolling sum of the headcount.

 

I have two tables in my Power BI Report:

- I have a table called Headcount which has a list of months.

2.PNG

- An Employee Table which has a list of Employees, their Hire Date and Termination Date

3.PNG

 

I've created a Headcount measure which calculates the headcount for a specific month, based on their hire date and termination date.

4.PNG

 

I tried to create another measure which then SUMs the 12 months rolling headcount, but I can't seem to get the right result.

 

5.PNG

 

For example, in January 2020 I would like the new column to have 155 because that is the sum of the Headcount between February 2019 and January 2020.

 

I've included the PBIX file here. Thanks in advance!

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

Hi @Anonymous ,

 

You could create the following two measures:

LastYearTest =
SUMX (
    FILTER (
        ALLSELECTED ( Headcount[StartOfMonth] ),
        DATEDIFF (
            Headcount[StartOfMonth],
            SELECTEDVALUE ( Headcount[StartOfMonth] ),
            MONTH
        ) = 12
    ),
    [_Headcount]
)
12MonthSum =
SUMX (
    FILTER (
        ALLSELECTED ( Headcount[StartOfMonth] ),
        Headcount[StartOfMonth] <= MAX ( Headcount[StartOfMonth] )
    ),
    [_Headcount] - [LastYearTest]
)

Here is the result.
1-1.PNG

 

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

View solution in original post

1 REPLY 1
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could create the following two measures:

LastYearTest =
SUMX (
    FILTER (
        ALLSELECTED ( Headcount[StartOfMonth] ),
        DATEDIFF (
            Headcount[StartOfMonth],
            SELECTEDVALUE ( Headcount[StartOfMonth] ),
            MONTH
        ) = 12
    ),
    [_Headcount]
)
12MonthSum =
SUMX (
    FILTER (
        ALLSELECTED ( Headcount[StartOfMonth] ),
        Headcount[StartOfMonth] <= MAX ( Headcount[StartOfMonth] )
    ),
    [_Headcount] - [LastYearTest]
)

Here is the result.
1-1.PNG

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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