March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
Greetings community!
I've been tasked with calculating the 1 year retention rate of newly hired employees month over month. I've spent a lot of time tweaking my DAX to achieve this, but have been unsuccessful to get the Date filter context to play nice. Hoping someone in the community can identify what I'm doing wrong.
.pbix and .xlsx that includes example of expected outcome are available on my google drive.
I have two fact tables and a Date Dimension Table I'm working with.
My current approach has been:
My Issue is that I've been unable to find a DAX measure that correctly identifies the terminated employees and maintains the row level date filter context. I either return a value on the grand total row only or nothing is returned.
Current Matrix Visual
Expected outcomes for July and August 2024
DAX Measures for identifying relevent terminations are:
TerminatedWithin1YearV1 =
VAR CurrentYear = YEAR(MAX('Date'[Date]))
VAR CurrentMonth = MONTH(MAX('Date'[Date]))
VAR FirstDayOfMonthPriorYear = DATE(CurrentYear - 1, CurrentMonth, 1)
VAR LastDayOfMonthPriorYear = EOMONTH(FirstDayOfMonthPriorYear, 0)
RETURN
CALCULATE(
DISTINCTCOUNT(Terms[Empl_ID]),
FILTER(
Terms,
Terms[Consecutive Tenure (Yrs)] < 1 &&
Terms[Empl_ID] IN
SELECTCOLUMNS(
FILTER(
Hires,
Hires[MostRecentHireDate] >= FirstDayOfMonthPriorYear &&
Hires[MostRecentHireDate] <= LastDayOfMonthPriorYear
),
"Empl_ID", Hires[Empl_ID]
)
)
)
AND
TerminatedWithin1YearV2 =
VAR SelectedDate = SELECTEDVALUE('Date'[Date]) -- Row-specific context
VAR CurrentYear = YEAR(SelectedDate)
VAR CurrentMonth = MONTH(SelectedDate)
VAR FirstDayOfMonthPriorYear = DATE(CurrentYear - 1, CurrentMonth, 1)
VAR LastDayOfMonthPriorYear = EOMONTH(FirstDayOfMonthPriorYear, 0)
VAR RelevantHires =
FILTER(
Hires,
Hires[MostRecentHireDate] >= FirstDayOfMonthPriorYear &&
Hires[MostRecentHireDate] <= LastDayOfMonthPriorYear
)
VAR RelevantTerms =
FILTER(
Terms,
Terms[Consecutive Tenure (Yrs)] < 1 &&
Terms[Empl_ID] IN SELECTCOLUMNS(RelevantHires, "Empl_ID", Hires[Empl_ID])
)
RETURN
CALCULATE(
DISTINCTCOUNT(Terms[Empl_ID]),
RelevantTerms,
REMOVEFILTERS('Date') -- Prevent interference from other filters
)
The date logic used in the v1 measure is the same that I used for the measure that counts the number of hires in the same month of the prior year. That measure is calculating correctly, however when I attempt that same approach with the Terms measure, I get no row level returns, only a grand total for one month.
Appreciate any insight the community can provide. Thanks in advance.
Jason
This can be simplified a bit.
You can then add logic to match the hire IDs to the termination IDs if needed.
Thanks for the simplified approach. Unfortunately, I'm not getting the sums I expect. I have modified the measure as you described and included the additional logic to match on the specific hires from the year prior. The measure is returning values much smaller than expected.
Revised measure with suggested logic:
TerminatedWithin1Year =
var md = min('Date'[Date])
RETURN CALCULATE(
DISTINCTCOUNT(Terms[Empl_ID]),
Terms[Term Date] in CALENDAR(EDATE(md,-12),md),
TREATAS(
VALUES('Hires'[Empl_ID]),
Terms[Empl_ID]
)
)
For July and August, the total hires matches my expected totals, but the terms do not
Based on the sample data provided, I am expecting 129 first year terms for July and 155 for August, but the measure is returning 18 and 7 respectively.
Thank you.
I refactored the formula to make it bulletproof - still am arriving at different numbers.
TerminatedWithin1Year =
VAR a =
CALCULATETABLE ( Hires, SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
VAR b =
ADDCOLUMNS (
a,
"termdate",
CALCULATE (
MAX ( Terms[Term Date] ),
TREATAS ( { [Empl_ID] }, Terms[Empl_ID] )
)
)
RETURN
COUNTROWS (
FILTER (
b,
COALESCE ( [termdate], dt"2030-01-01" ) < EDATE ( [MostRecentHireDate], 12 )
)
)
I guess some of the confusion is around the mismatch between Fiscal and Calendar years.
Thanks for your continued assistance. I'll take a closer look, remove FY references from the visuals to write that off as a possible issue and see what results I come up with.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
90 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
70 | |
68 |