Employee Attrition Rate Calculator (Power BI Logic)
Calculation Results
Average Headcount:0
Attrition Rate:0.00%
Power BI DAX Measure Snippet
Attr Rate =
VAR Leavers = [Total Leavers]
VAR StartHC = [Starting Headcount]
VAR EndHC = [Ending Headcount]
VAR AvgHC = DIVIDE(StartHC + EndHC, 2)
RETURN
DIVIDE(Leavers, AvgHC, 0)
*Copy this code into a New Measure in Power BI Desktop.
How to Calculate Attrition Rate in Power BI
Calculating attrition is a fundamental requirement for HR analytics dashboards. In Power BI, this involves handling time intelligence, employee data snapshots, and standard HR formulas. This guide explains the logic behind the calculation and how to translate it into Data Analysis Expressions (DAX).
The Standard Formula
While there are several variations (such as annualized attrition), the standard formula used in most HR dashboards is:
Attrition Rate = (Total Leavers / Average Headcount) × 100
Where:
Total Leavers: The count of employees who left the organization during the selected period.
Average Headcount: (Starting Headcount + Ending Headcount) / 2.
Step-by-Step Power BI Implementation
1. Data Modeling
To calculate this effectively in Power BI, you need an Employee Fact Table (containing start dates and separation dates) and a standard Date Table. Ensure there is an active relationship between your Date Table and the Employee table (usually on the Active Date or Separation Date, though inactive relationships with USERELATIONSHIP are common for handling both).
2. Creating Basic Measures
Before creating the final percentage, define your base measures:
The challenge in Power BI is calculating the "Starting" and "Ending" headcount dynamically based on the slicer selection (e.g., if a user selects "Q1 2023").
You typically use FIRSTDATE() and LASTDATE() logic combined with CALCULATE to determine the headcount at the boundaries of the selected period.
Frequently Asked Questions
Why is my Attrition Rate showing as infinity in Power BI?
This usually happens if your Average Headcount is 0 or BLANK. Always use the DIVIDE() function in DAX rather than the / operator. The DIVIDE function handles division by zero gracefully by returning a blank or an alternate result (like 0).
Should I use Month-end or Daily Average Headcount?
The standard simplified formula uses the average of the starting and ending balances. However, for highly volatile workforces, calculating a daily average headcount using AVERAGEX(VALUES('Date'[Date]), [Daily Headcount]) yields a more precise attrition rate.
How do I annualize the rate for a single month?
If you are calculating attrition for January only, a 2% rate might look low, but annualized it is 24%. To annualize in DAX: [Attrition Rate] * (12 / COUNTROWS(VALUES('Date'[Month]))).
function calculateAttrition() {
// 1. Get input values
var startCountStr = document.getElementById("startHeadcount").value;
var endCountStr = document.getElementById("endHeadcount").value;
var leaversStr = document.getElementById("totalLeavers").value;
// 2. Parse values
var startCount = parseFloat(startCountStr);
var endCount = parseFloat(endCountStr);
var leavers = parseFloat(leaversStr);
// 3. Validation
if (isNaN(startCount) || isNaN(endCount) || isNaN(leavers)) {
alert("Please enter valid numeric values for all fields.");
return;
}
if (startCount < 0 || endCount < 0 || leavers 0) {
attritionRate = (leavers / avgHeadcount) * 100;
} else {
attritionRate = 0;
}
// 6. Display Results
document.getElementById("resAvgHeadcount").innerHTML = avgHeadcount.toLocaleString('en-US', {minimumFractionDigits: 1, maximumFractionDigits: 1});
document.getElementById("resAttritionRate").innerHTML = attritionRate.toFixed(2) + "%";
// 7. Generate Dynamic DAX for the user
var daxTemplate = "Attrition Rate Measure = \n" +
"VAR Leavers = " + leavers + " // Or replace with [Total Leavers] Measure\n" +
"VAR StartHC = " + startCount + " // Or replace with [Opening Headcount]\n" +
"VAR EndHC = " + endCount + " // Or replace with [Closing Headcount]\n" +
"VAR AvgHC = DIVIDE(StartHC + EndHC, 2)\n" +
"RETURN\n" +
" DIVIDE(Leavers, AvgHC, 0)";
document.getElementById("daxOutput").innerText = daxTemplate;
// Show result box
document.getElementById("results").style.display = "block";
}