The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello Experts,
Need your help in getting the employee retention. In my model, unfortunately, I don't have an Employee Dimension table, therefore, this is not an option for me. I have tried to use DAX to get the desired output but not sure what is going on here. My task is to identify employees retained currently compared to a past period and report based on the past period dimensions (Dept, Country, etc.)
I have the sample PIB file and Data file including the desired output attached for your kind reference.
Sample files : https://drive.google.com/drive/folders/1qqap1uLbkKGQIZpHjnA_2vwdcj1Um5rp?usp=sharing
Below is my DAX code. I have even tried to add LOOUPVALUE and some other methods, but all failed to provide me with what I wanted.
Original Department | Count of Retained Employees |
DeptA | 6 |
DeptB | 4 |
DeptC | 3 |
Grand Total | 13 |
Solved! Go to Solution.
Hi @MrSam please check this measure
Hi @MrSam please check this measure
Hi @techies Thank you.
I was able to get the code to work once I placed the filters using dimensions. However, to make the cross filtering work properly, I have to modify the second half of the code you have provided.
Hi @techies
I'll take back my previous comment. I was able to get the filters added. I have to rely on the Departments from the dimension table to get it work. However, I had to do a modification to the second half of the code so it was working properly when cross filters were applied.
@techies Thank you. This works but as soon as I introduce the filter to removed DeptD, it breaks. Any solution to include that filter too.
@bhanu_gautam
Thank you. However, I am getting error "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."
@MrSam , Try using
DAX
Retention =
VAR _StartDate = EOMONTH(MAX('Date'[Date]), -2) -- Get end of the month, 2 months back
-- Base Headcount Data - 2 Months back (Ignores Date slicer)
VAR _BaseHeadcount =
SELECTCOLUMNS(
CALCULATETABLE(
'Headcount',
ALL('Date'), -- Ignores Date slicer
'Headcount'[Month] = _StartDate,
NOT 'Headcount'[Department] IN {"DeptD"}
),
"Employee ID", [Employee ID],
"Department", [Department]
)
-- Current Headcount Data (Current Period)
VAR _CurrentHeadcount =
SELECTCOLUMNS(
FILTER(
'Headcount',
NOT 'Headcount'[Department] IN {"DeptD"}
),
"Employee ID", [Employee ID],
"Department", [Department]
)
-- Find the retained employees
VAR _RetainedEmployees =
NATURALINNERJOIN(_BaseHeadcount, _CurrentHeadcount)
RETURN
SUMMARIZE(
_RetainedEmployees,
[Department],
"Count of Retained Employees", COUNTROWS(_RetainedEmployees)
)
Proud to be a Super User! |
|
User | Count |
---|---|
11 | |
9 | |
6 | |
6 | |
5 |
User | Count |
---|---|
24 | |
14 | |
14 | |
9 | |
7 |