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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Turnover calculation in DAX

I'm trying to do a trend line for turnover, where the calculation is Total leavers in the week / Average weekly headcount in the preceeding 52 weeks.

 

I have managed to make it work using a fixed 52 week window to the current week, but can't figure out how to make it dynamic to the week being reported for:

 

Turnover = DIVIDE(COUNTROWS('leavers'),CALCULATE(COUNTROWS('employees'),FILTER(ALL(weeklist),'weeklist'[Offset to Current week] >= -52)) / 52)

 

I have 3 tables;

weeklist (A calendar, which lists all the weeks and their offset to now)

WeekOffset to Current week
2020Wk01-15
2020Wk02-14

 

leavers (lists leavers and the week they left):

Employee NoWeek left (Joined to Week column of weeklist table)
1012020Wk02
1022020Wk04

 

employees (lists all active employees for every week):

EmployeeWeek (Joined to Week column of weeklist table)Note
1012020Wk01 
1022020Wk01 
1032020Wk01 
1022020Wk02 
1032020Wk02 
1042020Wk03New Starter
1032020Wk04 
1042020Wk04 

 

Obviously it's difficult to demonstrate 52 weeks history of the tables in a quick structure example, but hopefully you get the idea!

 

So what I'm trying to do in DAX that does the same as above, but rather than going back 52 weeks from now, it goes back 52 weeks from the week being reported for - so Reporting for week 2020Wk02 would see that it's offset by -14 from now and then return the average headcount between weeks 2019Wk03 and 2020Wk02 (the offset range is -65 to -14) and for week 2020Wk03 it would return the average between 2019Wk04 and 2020Wk03 and so on.

 

I'm really struggling to make this dynamic so that i can pop it into a trend chart and it will always look at the relative 52 week offset. Help would be very much appreciated.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

According to your sample tables, would you please refer to the measure below:

 

Turnover =

VAR a =

    COUNTROWS ( leavers )

VAR b =

    CALCULATE (

        COUNTROWS ( employees ),

        FILTER (

            ALL ( employees ),

            RELATED ( weeklist[Offset to Current week] )

                >= MAX ( weeklist[Offset to Current week] ) - 52

                && RELATED ( weeklist[Offset to Current week] )

                    < MAX ( weeklist[Offset to Current week] )

        )

    ) / 52

RETURN

    DIVIDE ( a, b )

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Please find the full solution attached. Handles the future and the past correctly.

 

Any questions and bugs - please let me know.

 

Best

D

amitchandak
Super User
Super User

Refer my blog for active/current employee : https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

file :https://www.dropbox.com/s/excoqikgpyz5zvk/Current_employee.pbix?dl=0

How to deal with weeks using rank : https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

 

See if these can help. Does your data do not have date?

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak no dates, only the weekly offset as demonstrated, all the data is a weekly snapshot. I will see if I can repurpose what you have linked. Thanks.

@Anonymous , Try with week rank.  Is the sample data you provide is best we can use?

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak the sample data was just to give an indication of the layout, obviously to do a rolling 52 weeks for the last 52 weeks trend, 104 weeks history would be required. Shall I upload sample data? What's the best way to do that? A PBIX file?

Hi @Anonymous ,

 

According to your sample tables, would you please refer to the measure below:

 

Turnover =

VAR a =

    COUNTROWS ( leavers )

VAR b =

    CALCULATE (

        COUNTROWS ( employees ),

        FILTER (

            ALL ( employees ),

            RELATED ( weeklist[Offset to Current week] )

                >= MAX ( weeklist[Offset to Current week] ) - 52

                && RELATED ( weeklist[Offset to Current week] )

                    < MAX ( weeklist[Offset to Current week] )

        )

    ) / 52

RETURN

    DIVIDE ( a, b )

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

@Anonymous , after removing sensetive information load it on one drive or dropbox and share the link here or PM me

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.