Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
DAX Experts,
My overall goal is to calculate the Retention Rate through a Date Hierarchy like Year -> Quarter -> Month.
Problem -> The part where I’m getting stuck is a “Starting” value which is aimed at getting the count of employees in the previous month period WHILE caring for the Quarter value (count in the last month of the quarter) and Year value (count in the last month of the year). So, If I slice by year, quarter, or month I get the right values when using a set of measures.
Desired Final Results:
December | 1172 | |||||||
Year | Count Active | Count Hires | Count Exits | Starting Count | Remaining Count | Retention Rate | Retention Rate PY | Retention Rate YOY% |
2021 | 1207 | 111 | 43 | 1172 | ||||
Q1 | 1184 | 11 | 0 | 1172 | ||||
January | 1189 | 2 | 0 | 1172 | ||||
February | 1180 | 1 | 0 | 1189 | ||||
March | 1184 | 8 | 0 | 1180 | ||||
Q2 | 1179 | 34 | 20 | 1184 | ||||
April | 1176 | 2 | 0 | 1184 | ||||
May | 1178 | 13 | 20 | 1176 | ||||
June | 1179 | 19 | 0 | 1178 | ||||
Q3 | 1207 | 66 | 23 | 1179 | ||||
July | 1188 | 21 | 20 | 1179 | ||||
August | 1187 | 19 | 3 | 1188 | ||||
September | 1207 | 26 | 0 | 1187 |
(THIS FORMULA IS WORKING THEY WAY I WANT)
Count Active =
VAR CountActive =
CALCULATE(
DISTINCTCOUNT(Turnover[Employee ID]),
LASTDATE(Turnover[Period])
)
RETURN
CountActive
(This is attempt #1 at starting that gets my months correct by my quarter and year aren’t correctly matching my table mockup above)
Starting Count =
CALCULATE(
[Count Active], DATEADD(Dates[Date],-1,MONTH)
)
(This is attempt #2 at starting that gets my Quarter and Year value to use the starting value of the first month in that period. However, now my months are not correctly picking up the previous month )
Starting Count =
VAR Countstart =
CALCULATE(
DISTINCTCOUNT(Turnover[Employee ID]),
FIRSTDATE(Turnover[Period])
)
RETURN
CALCULATE(
Countstart, DATEADD(Dates[Date],-1,MONTH)
)
Details:
Turnover Table Structure
Employee ID | Gender Code | EEO Code | DeptDesc | Hire Date | Termination Date | Job Grade | Period |
12345 | F | 2 | Dept 10 | 12/3/2018 | 1/1/1900 | A6U | 10/31/2021 |
12346 | F | 2 | Dept 10 | 5/9/2011 | 1/1/1900 | T3M | 10/31/2021 |
12347 | M | 2 | Dept 10 | 5/29/2012 | 1/1/1900 | T3M | 10/31/2021 |
12348 | F | 2 | Dept 10 | 12/12/2011 | 1/1/1900 | T3M | 10/31/2021 |
12349 | F | 2 | Dept 10 | 1/30/2012 | 4/3/2021 | T3M | 10/31/2021 |
12350 | F | 2 | Dept 14 | 10/1/2007 | 1/1/1900 | T3M | 10/31/2021 |
12351 | M | 2 | Dept 14 | 10/15/2007 | 1/1/1900 | B2M | 10/31/2021 |
12352 | F | 2 | Dept 10 | 5/16/2016 | 1/1/1900 | B2M | 10/31/2021 |
12345 | F | 2 | Dept 10 | 12/3/2018 | 1/1/1900 | A6U | 11/31/2021 |
12346 | F | 2 | Dept 10 | 5/9/2011 | 1/1/1900 | T3M | 11/31/2021 |
12347 | M | 2 | Dept 10 | 5/29/2012 | 1/1/1900 | T3M | 11/31/2021 |
12348 | F | 2 | Dept 10 | 12/12/2011 | 1/1/1900 | T3M | 11/31/2021 |
12349 | F | 2 | Dept 10 | 1/30/2012 | 4/3/2021 | T3M | 11/31/2021 |
12350 | F | 2 | Dept 14 | 10/1/2007 | 1/1/1900 | T3M | 11/31/2021 |
12351 | M | 2 | Dept 14 | 10/15/2007 | 1/1/1900 | B2M | 11/31/2021 |
12352 | F | 2 | Dept 10 | 5/16/2016 | 1/1/1900 | B2M | 11/31/2021 |
Thank you in advance.
Solved! Go to Solution.
Hi, @bwarner87 ;
I made a simple example about the count of last month, last quarter and last year. In my example, I used sum, you can change it to discount.
Starting Count =
IF (
ISINSCOPE ( 'Table'[date].[Month] ),
CALCULATE ( SUM ( [value] ), PREVIOUSMONTH ( 'Table'[date] ), ALL ( 'Table' ) ),
IF (
ISINSCOPE ( 'Table'[date].[Quarter] ),
CALCULATE (
SUM ( [value] ),
PREVIOUSQUARTER ( 'Table'[date] ),
ALL ( 'Table' )
),
IF (
ISINSCOPE ( 'Table'[date].[Year] ),
CALCULATE ( SUM ( [value] ), PREVIOUSYEAR ( 'Table'[date] ), ALL ( 'Table' ) )
)
)
)
The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @bwarner87 ;
I made a simple example about the count of last month, last quarter and last year. In my example, I used sum, you can change it to discount.
Starting Count =
IF (
ISINSCOPE ( 'Table'[date].[Month] ),
CALCULATE ( SUM ( [value] ), PREVIOUSMONTH ( 'Table'[date] ), ALL ( 'Table' ) ),
IF (
ISINSCOPE ( 'Table'[date].[Quarter] ),
CALCULATE (
SUM ( [value] ),
PREVIOUSQUARTER ( 'Table'[date] ),
ALL ( 'Table' )
),
IF (
ISINSCOPE ( 'Table'[date].[Year] ),
CALCULATE ( SUM ( [value] ), PREVIOUSYEAR ( 'Table'[date] ), ALL ( 'Table' ) )
)
)
)
The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
98 | |
78 | |
66 | |
53 |
User | Count |
---|---|
139 | |
100 | |
95 | |
85 | |
63 |