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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Megha2498
Frequent Visitor

Attrition DAX for HR Dashboard

Hi,

I need help in getting the DAX for calculating 3 types of attrition :

I have been breaking my head for a few weeks , no luck. Need help here

 

1. Monthly Attrition rate = Total termination for the month / average of Opening and Closing HC in the month. (Opening is closing of Previous Month)

2. YTD Attrition rate = Total terminations till date in the FY / Average of Opening and Closing balance till date in the FY. 

FY starts as on 01, April every year. (Opening of april is March value of every year)

3. Projected Attrition Rate = (Actual leavers + Estimated leavers) / Average of Opening and Closing balance till date

Estimated Leavers = Sum of actual terminations / # of months pasted by in the FY  (Opening of april is March value of every year)

 

Below is the Expected result and sample data 

 

Sample Data

Reporting DateEmployee IDStatusTermination Date
3/31/20231Active 
3/31/20232Active 
3/31/20233Active 
3/31/20234Active 
3/31/20235Active 
3/31/20236Active 
4/30/20231Active 
4/30/20232Active 
4/30/20233Terminated4/15/2023
4/30/20234Active 
4/30/20235Active 
4/30/20236Active 
5/31/20231Terminated5/2/2023
5/31/20232Active 
5/31/20234Active 
5/31/20235Active 
5/31/20236Active 
5/31/20237Active 
5/31/20238Active 
5/31/20239Active 
6/30/20232Active 
6/30/20234Active 
6/30/20235Active 
6/30/20236Terminated6/5/2023
6/30/20237Terminated6/5/2023
6/30/20238Active 
6/30/20239Active 
6/30/202310Active 
6/30/202311Active 
6/30/202312Active 
6/30/202313Active 
7/31/20232Active 
7/31/20234Active 
7/31/20235Active 
7/31/20238Active 
7/31/20239Active 
7/31/202310Active 
7/31/202311Active 
7/31/202312Active 
7/31/202313Active 
8/31/20232Active 
8/31/20234Active 
8/31/20235Active 
8/31/20238Active 
8/31/20239Active 
8/31/202310Active 
8/31/202311Active 
8/31/202312Active 
8/31/202313Active 
9/30/20232Active 
9/30/20234Terminated9/20/2023
9/30/20235Active 
9/30/20238Active 
9/30/20239Active 
9/30/202310Active 
9/30/202311Active 
9/30/202312Active 
9/30/202313Active 
10/30/20232Active 
10/30/20235Active 
10/30/20238Active 
10/30/20239Active 
10/30/202310Active 
10/30/202311Active 
10/30/202312Active 
10/30/202313Active 
11/30/20232Active 
11/30/20235Active 
11/30/20238Active 
11/30/20239Active 
11/30/202310Active 
11/30/202311Active 
11/30/202312Active 
11/30/202313Active 
12/30/20232Active 
12/30/20235Active 
12/30/20238Active 
12/30/20239Active 
12/30/202310Active 
12/30/202311Active 
12/30/202312Active 
12/30/202313Active 
1 ACCEPTED SOLUTION

PBI file attached.  Our answers differ (as compared to what is shown in your Google sheets file) from Sep 2023 onwards because in the PBI file, there is churn in Sep 2023.

Hope this helps.

Ashish_Mathur_0-1713842819553.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

16 REPLIES 16
NikharKedia
Regular Visitor

Hi guys,

 

How do I create the base dataset that you have used at the start if I have an employee table with simple list of employees with start dates, status and end dates if terminated. Like below.

 

NameStatusStart DateEnd Date
1Terminated - other9/16/20209/24/2024
2Terminated - left ACN9/24/20226/5/2024
3Active8/20/2018 
4Active9/17/2018 
5Active9/17/2018 
6Active9/17/2018 
7Active9/17/2018 
8Active9/17/2018 
9Active9/24/2018 
10Onboarding10/1/2024 
11Terminated - different ACN project6/4/20214/9/2024
12Terminated - planned reduction9/3/20196/4/2024
13Active12/17/2018 
14Active10/1/2020 
15Terminated - AEP requested9/9/20216/12/2024
16Active11/12/2018 
17Active11/26/2018 
18Active11/26/2018 
19Active11/26/2018 
20Active12/17/2018 
21Terminated - other1/17/20229/19/2024
22Active9/24/2018 
23Active11/26/2018 
24Terminated - left ACN5/21/20231/8/2024
25Active9/17/2018 
26Active11/12/2018 

thanks,

Nikhar

Hi,

What is your expected result?  Give a proper explanation.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

 

I am trying to get to the similar calculations as you had provided before. Attrition Rate%; Attrition Rate YTD; etc. My challenge is that my starting point is different. Instead of the monthly reporting data, I have an employee table with thier starting dates and ending dates. Is there someway for me to transform my data to I get the same starting point as the original post? or is it possible for me to calculate attrition rate directly from my data.

 

thanks,

Nikhar

Hi,

To create one row for each month between start date and end date, refer to the solution in this article - Generating Rows by Month for Date Ranges in Power Query | by Daniel Marsh-Patrick | Daniel Marsh-Pat...


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
johnbasha33
Super User
Super User

@Megha2498 

To calculate the three types of attrition rates (Monthly, YTD, and Projected) in Power BI using DAX, you can follow these steps:

1. **Monthly Attrition Rate**:
```DAX
Monthly Attrition Rate =
VAR PreviousMonthHC = CALCULATE(SUM('Table'[Status] = "Active"), PREVIOUSMONTH('Table'[Reporting Date]))
VAR CurrentMonthTerminations = CALCULATE(COUNTROWS('Table'), 'Table'[Status] = "Terminated")
RETURN
DIVIDE(CurrentMonthTerminations, (PreviousMonthHC + SUM('Table'[Status] = "Active")) / 2, 0)
```

2. **YTD Attrition Rate**:
```DAX
YTD Attrition Rate =
VAR FYStartDate = DATE(YEAR(MIN('Table'[Reporting Date])) + IF(MONTH(MIN('Table'[Reporting Date])) >= 4, 0, -1), 4, 1)
VAR CurrentFYTerminations = CALCULATE(COUNTROWS('Table'), 'Table'[Status] = "Terminated", 'Table'[Reporting Date] >= FYStartDate)
VAR OpeningBalance = CALCULATE(SUM('Table'[Status] = "Active"), 'Table'[Reporting Date] = EOMONTH(FYStartDate, -1))
VAR ClosingBalance = CALCULATE(SUM('Table'[Status] = "Active"), 'Table'[Reporting Date] = LASTDATE('Table'[Reporting Date]))
RETURN
DIVIDE(CurrentFYTerminations, (OpeningBalance + ClosingBalance) / 2, 0)
```

3. **Projected Attrition Rate**:
```DAX
Projected Attrition Rate =
VAR CurrentFYTerminations = CALCULATE(COUNTROWS('Table'), 'Table'[Status] = "Terminated")
VAR NumberOfMonthsPassed = DATEDIFF(MIN('Table'[Reporting Date]), TODAY(), MONTH)
VAR OpeningBalance = CALCULATE(SUM('Table'[Status] = "Active"), 'Table'[Reporting Date] = EOMONTH(FYStartDate, -1))
VAR ClosingBalance = CALCULATE(SUM('Table'[Status] = "Active"), 'Table'[Reporting Date] = LASTDATE('Table'[Reporting Date]))
RETURN
DIVIDE(CurrentFYTerminations + CurrentFYTerminations / NumberOfMonthsPassed, (OpeningBalance + ClosingBalance) / 2, 0)
```

Replace `'Table'` with the actual name of your table. These measures assume you have a table named `'Table'` containing the sample data provided.

Once you've created these measures, you can add them to your Power BI report and use them in visualizations to display the attrition rates. Make sure to adjust the calculations and filters as needed based on your specific data model and requirements.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

This doenst work because the use of the Sum function is wrong.

Megha2498
Frequent Visitor

Expected results:

Monthly Attrition 

MonthHeadcountTerminationsOpening HeadcountClosing HeadcountAttrition %
March60   
April516518.18%
May715716.67%
June927925.00%
July90990.00%
August90990.00%
September819811.76%
October80880.00%
November80880.00%
December80880.00%

 

Projected Attrition result :

MonthHeadcountTerminationsOpening HeadcountClosing Headcountaverage HeadcountEstimated LeaversAttrition %
April51655.5118.18%
May71576.5130.77%
June92797.5144.44%
July90997.5157.78%
August     168.44%
September     177.33%
October     184.95%
November     191.62%
December     097.54%

 

 

YTD Attrition expected result:

MonthHeadcountTerminationsOpening HeadcountClosing Headcountaverage HeadcountAttrition %
April51655.518.18%
May71576.530.77%
June92797.553.33%
July90997.553.33%
August90997.553.33%
September8198771.43%
October8088771.43%
November8088771.43%
December8088771.43%

Hi,

PBI file attached.  Cannot understand the calculation of estimated leavers

Hope this helps.

Ashish_Mathur_0-1713598815610.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

 

Thankyou very much for your response. This did help a lot. 

Very grateful to you 🙂

 

Explaining the project attrition calculation again :

 

Considering we are now in Aug 2023:

- April - Jul will have the YTD calculation based on actuals. Aug - March will have projected Attrition.

 

Projected Attrition = (Actual leavers + Estimated leavers) / Average of Opening and Closing  balance till date

 

Estimated Leavers Aug  = Sum of actual leavers till date / # of months passed by in the FY+1

Estimated leavers for Aug = (Sum of leavers from Apr - Jul) / 5

5 = No of months passed by in the FY (April, May, June, Jul+ Aug)

 

Estimated leavers for Sep = (Sum of leavers from Apr - Jul) / 6

6 = No of months passed by in the FY (April, May, June, Jul, Aug +Sep)

 

Estimated leavers for Oct = (Sum of leavers from Apr - Jul) / 7

7 = No of months passed by in the FY (April, May, June, Jul, Aug, Sep+ Oct)

 

Below is the expected results table:

Please help on this and let me know if you have any questions.

Very g        rateful to you! 🙂

FY YearYearMonthHeadcountTerminationsOpening HeadcountClosing Headcountaverage HeadcountEstimated LeaversAttrition %
FY232023April51655.5  
FY232023May71576.5  
FY232023June92797.5  
FY232023July90997.5  
FY232023August     168.44%
FY232023September     177.33%
FY232023October     184.95%
FY232023November     191.62%
FY232023December     097.54%

You are welcome.  It is difficult to visualise your requirement because April (the month in which we are), is the first month of the FY and therefore all months of this FY should be estimated calculations.

Anyways, share the download link of an Excel worksheet and in there, via formulas, show the calculation of estimated leavers and estimated attrition % (the last 2 columns which you have shown in your table). 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Sure, Here you go.

Link to excel file with the calculation and formula

Link 

 

 

PBI file attached.  Our answers differ (as compared to what is shown in your Google sheets file) from Sep 2023 onwards because in the PBI file, there is churn in Sep 2023.

Hope this helps.

Ashish_Mathur_0-1713842819553.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thankyou so much for help! 

You are truely Genius 🙂 This also helped me to understand the way we could breakdown the DAX to get a solution. 

You are welcome.  Thank you for your kind words.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Access denied message.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Megha2498 I can't get your numbers for Mothly Attrition rate. 1 leaver and 5 headcount at the end of the month gives me 1/5 or 20% ??

Monthly Attrition = 
    VAR __Count = COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('Table', [Status] = "Active"), "__ID", [Employee ID])))
    VAR __Term = COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('Table', [Status] = "Terminated"), "__ID", [Employee ID])))
    VAR __Result = DIVIDE( __Term, __Count, 0 ) + 0
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.