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
Megha2498
Frequent Visitor

undefined

Hi All,

 

I need to create a power BI with attrition rate calculation that can drill down by Department, country and manager. I have two files, headcount and Termination. 

Need help in DAX

10 REPLIES 10
Megha2498
Frequent Visitor

Here is the sample data:

Active employee table:

Reporting DateEmployee IDNameDepartmentCountry
12/31/2023Empy 1AFinanceIndia
12/31/2023Empy 2BHRFinland
12/31/2023Empy 3CSupplyUS
12/31/2023Empy 4DFinanceCanada
12/31/2023Empy 5EFinanceIndia
12/31/2023Empy 6FHRFinland
12/31/2023Empy 7GSupplyUS
12/31/2023Empy 8HITCanada
12/31/2023Empy 9IITIndia
12/31/2023Empy 10JITFinland
12/31/2023Empy 11KSupplyUS
12/31/2023Empy 12LHRCanada
12/31/2023Empy 13MFinanceCanada
1/31/2024Empy 1AFinanceIndia
1/31/2024Empy 2BHRFinland
1/31/2024Empy 3CSupplyUS
1/31/2024Empy 4DFinanceCanada
1/31/2024Empy 5EFinanceIndia
1/31/2024Empy 6FHRFinland
1/31/2024Empy 7GSupplyUS
1/31/2024Empy 8HITCanada
1/31/2024Empy 9IITIndia
1/31/2024Empy 11KSupplyUS
1/31/2024Empy 12LHRCanada
1/31/2024Empy 13MFinanceCanada
2/29/2024Empy 1AFinanceIndia
2/29/2024Empy 2BHRFinland
2/29/2024Empy 5EFinanceIndia
2/29/2024Empy 6FHRFinland
2/29/2024Empy 7GSupplyUS
2/29/2024Empy 8HITCanada
2/29/2024Empy 9IITIndia
2/29/2024Empy 11KSupplyUS
2/29/2024Empy 12LHRCanada
2/29/2024Empy 13MFinanceCanada
2/29/2024Empy 14NHRIndia

 

Terminated employees table:

Employee IDNameDepartmentCountryTermination date
Empy 3CSupplyUS2/2/2024
Empy 4DFinanceCanada2/15/2024
Empy 10JITFinland1/5/2024

 

Expected calculation:

Monthly Attrition Rate calculation (Dec - Jan)

12/31/2023Opening HC13
1/31/2024Closing HC12
Dec - JanTerminations1
  1/average (13,12)
 Attrition rate8.0%

 

YTD Attrition Rate calculation (Dec - Feb)

12/31/2023Opening HC13
2/29/2024Closing HC11
Dec - JanTerminations3
  3 /average (13,11)
 Attrition rate25.0%

 

I should be able to filter this calculation by country and department.  

hi @Megha2498 

 

Please try these. Ignore previous measures as I did not take terminated employee count from Terminated table. Apology for that.

 

Note that these measures are based on assumption that dates in Active employee table will always be monthend dates and reporting is based on these dates and only for terminated employee count we need to refer to Terminated employee table.

 

---------------------------------------------------------------------------------------------------

Measure =
VAR _MinDate = CALCULATE(MIN('ActiveEmployee'[Reporting Date]), REMOVEFILTERS('ActiveEmployee'[Reporting Date]))
VAR _SelectedReportDt = SELECTEDVALUE('ActiveEmployee'[Reporting Date])
VAR _PreviousMth = EOMONTH(_SelectedReportDt,-1)
VAR _CurrentMthCount = CALCULATE(COUNT('ActiveEmployee'[Employee ID]))
VAR _PrevMthCount = CALCULATE(COUNT('ActiveEmployee'[Employee ID]), REMOVEFILTERS('ActiveEmployee'[Reporting Date]), 'ActiveEmployee'[Reporting Date] = _PreviousMth)
VAR _Terminated = CALCULATE(COUNT(Termination[Employee]), REMOVEFILTERS(), Termination[Termination date] >= _PreviousMth && Termination[Termination date] <= _SelectedReportDt)
RETURN IF(
            _SelectedReportDt = _MinDate || NOT(HASONEFILTER('ActiveEmployee'[Reporting Date])),
            BLANK(),
            DIVIDE((_Terminated), ((_PrevMthCount+_CurrentMthCount)/2))
    )

---------------------------------------------------------------------------------------------------

Measure YTD =
VAR _MinDate = CALCULATE(MIN('ActiveEmployee'[Reporting Date]), REMOVEFILTERS('ActiveEmployee'[Reporting Date]), YEAR('ActiveEmployee'[Reporting Date]) = YEAR(TODAY()) )
VAR _MaxDateLastYear = EOMONTH(_MinDate, -1)
VAR _MaxDateCurrYr = CALCULATE(MAX('ActiveEmployee'[Reporting Date]), REMOVEFILTERS('ActiveEmployee'[Reporting Date]))
VAR _CurrentCount = CALCULATE(COUNT('ActiveEmployee'[Employee ID]), REMOVEFILTERS(), 'ActiveEmployee'[Reporting Date] = _MaxDateCurrYr)
VAR _PrevCount = CALCULATE(COUNT('ActiveEmployee'[Employee ID]), REMOVEFILTERS('ActiveEmployee'[Reporting Date]), 'ActiveEmployee'[Reporting Date] = _MaxDateLastYear)
VAR _Terminated = CALCULATE(COUNT(Termination[Employee]), REMOVEFILTERS(), Termination[Termination date] >= _MaxDateLastYear && Termination[Termination date] <= _MaxDateCurrYr)
RETURN DIVIDE((_Terminated), ((_PrevCount+_CurrentCount)/2))
 
-------------------------------------------------------------------------------------------------------------
 
talespin_0-1709899191623.png

 

 

 

Thankyou for quick response.

Sorry for confusion, the DAX is not helping.

Below is the corrected dataset:

 

I need help in creating 2 DAX. 

1. Monthly Attrition Rate -> Total termination in previous month/ Average of (Previous HC + Current HC)

2. YTD / Cumulative Attrition Rate -> Total terminations from April 01 / Average of (HC in April 01 + Current HC)

 

 

Example:

Monthly Attrition Rate for Jun -> Terminations in Jun / Average (HC in May + HC in Jun)

YTD / Cumulative Attrition Rate for Jun -> Terminations From April - jun / Average ( HC in April + HC in Jun)

 

YTD / Cumulative Attrition Rate for Jul = Terminations From April - jul / Average ( HC in April + HC in Jul)

Below is the sample data:

 

 

Reporting DateEmployee IDEmployee NameDepartmentCountryStatusTerminated Date
4/30/2023Employee 1ABCFinanceFinlandActive 
4/30/2023Employee 2ABCHRUSActive 
4/30/2023Employee 3ABCITCanadaActive 
4/30/2023Employee 4ABCSCMIndiaActive 
4/30/2023Employee 5ABCFinanceFinlandActive 
4/30/2023Employee 6ABCITUSTerminated4/2/2023
4/30/2023Employee 7ABCHRIndiaTerminated4/10/2023
5/31/2023Employee 1ABCFinanceFinlandActive 
5/31/2023Employee 2ABCHRUSActive 
5/31/2023Employee 3ABCITCanadaTerminated5/15/2023
5/31/2023Employee 4ABCSCMIndiaActive 
5/31/2023Employee 5ABCFinanceFinlandActive 
5/31/2023Employee 8ABCITUSActive 
5/31/2023Employee 9ABCHRIndiaActive 
5/31/2023Employee 10ABCHRIndiaActive 
5/31/2023Employee 11ABCHRIndiaActive 
5/31/2023Employee 12ABCHRIndiaActive 
5/31/2023Employee 13ABCHRIndiaActive 
5/31/2023Employee 14ABCHRIndiaActive 
6/30/2023Employee 1ABCFinanceFinlandActive 
6/30/2023Employee 2ABCHRUSActive 
6/30/2023Employee 4ABCSCMIndiaActive 
6/30/2023Employee 5ABCFinanceFinlandActive 
6/30/2023Employee 8ABCITUSActive 
6/30/2023Employee 9ABCHRIndiaActive 
6/30/2023Employee 10ABCHRIndiaActive 
6/30/2023Employee 11ABCHRIndiaTerminated6/27/2023
6/30/2023Employee 12ABCHRIndiaTerminated6/27/2023
6/30/2023Employee 13ABCHRIndiaActive 
6/30/2023Employee 14ABCHRIndiaActive 
6/30/2023Employee 15ABCHRIndiaActive 
6/30/2023Employee 16ABCHRIndiaActive 
6/30/2023Employee 17ABCHRIndiaActive 
6/30/2023Employee 18ABCHRIndiaActive 
6/30/2023Employee 19ABCHRIndiaActive 
6/30/2023Employee 20ABCHRIndiaActive 
6/30/2023Employee 21ABCHRIndiaActive 
7/31/2023Employee 1ABCFinanceFinlandTerminated7/1/2023
7/31/2023Employee 2ABCHRUSActive 
7/31/2023Employee 4ABCSCMIndiaActive 
7/31/2023Employee 5ABCFinanceFinlandActive 
7/31/2023Employee 8ABCITUSActive 
7/31/2023Employee 9ABCHRIndiaActive 
7/31/2023Employee 10ABCHRIndiaActive 
7/31/2023Employee 13ABCHRIndiaActive 
7/31/2023Employee 14ABCHRIndiaActive 
7/31/2023Employee 15ABCHRIndiaActive 
7/31/2023Employee 16ABCHRIndiaActive 
7/31/2023Employee 17ABCHRIndiaActive 
7/31/2023Employee 18ABCHRIndiaActive 
7/31/2023Employee 19ABCHRIndiaActive 
7/31/2023Employee 20ABCHRIndiaActive 
7/31/2023Employee 21ABCHRIndiaActive 

hi @Megha2498 

 

Please share 2024 data and end result you expect.

 

Also please comfirm if you are using single table or multiple tables like before?

Incorrect.

The data is coming two different tables, should I combine to use this solution?

Incorrect

YTD Calculation is not helping. 

The data is in two tables. "Active employee list" and "termination List"

hi @Megha2498 

 

Please ignore above measure, will repost.

 

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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