Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
So I'm trying to create a measure that returns the 12-month staff attrition for teams within an organization, i.e. what percentage of staff leave over a 12 month period.
My sources are lists of staff as at the start dates of months, i.e. I have the staff list as at August 1, 2018, then a staff list as at September 1, 2018, then a staff list as at October 1, 2018, etc. The staff lists include team information. I have added a column to these lists indicating the month of the staff list, and I have appended them into a single query called 'Employee List'.
Actual Month (of List) | Employee ID | Team |
August 2017 | 634123 | Finance |
One way I thought I could create the attrition measure was by creating a calculated column that for each row looks at the actual month of the staff list from which that employee entry comes (say August 2017), then goes 12 months ahead of that (August 2018; let's say based on another column 'my + 12'), then counts rows later on in the table where the actual month matches this 'my +12', as well as the employee ID and team. If the count returns 1, then the staff member was found in the same team 12 months later so hasn't moved and so "No Change"; if it returns 0 then the staff member wasn't found so must have moved and thus it's "Left".
Actual Month (of List) | Employee ID | Team | my + 12 | No Change/Left |
August 2017 | 634123 | Finance | August 2018 | No Change |
… |
|
|
|
|
August 2018 | 634123 | Finance | August 2019 | - |
The issue is: how would I write this in DAX? I want to write CALCULATE(COUNTROWS('Employee List'),(current row's)'Employee List'[my +12]=(any rows in the table's)'Employee List'[Actual Month],(current row's)'Employee List'[Employee ID]=(any row in the table's)'Employee List'[Employee ID],(current row's)'Employee List'[Team]=(any row in the table's)'Employee List'[Team]), but as you can see, how do I deal with the shifting contexts I want to refer to? Or is there a better way to figure out the measure I'm wanting, given my data sources?
Any help would be greatly appreciated!
Solved! Go to Solution.
Hi @Anonymous ,
Suppose [Actual Month (of List)] is set to Date type.
Please refer to below formulas to create calculated columns.
my + 12 = LOOKUPVALUE ( staff[Actual Month (of List)], staff[Employee ID], staff[Employee ID], staff[Actual Month (of List)].[Month], staff[Actual Month (of List)].[Month], staff[Actual Month (of List)].[Year], staff[Actual Month (of List)].[Year] + 1 ) No Change/Left = IF ( staff[my + 12] <> BLANK (), "No change", "Left" )
Best regards,
Yuliana Gu
Hi @Anonymous ,
Suppose [Actual Month (of List)] is set to Date type.
Please refer to below formulas to create calculated columns.
my + 12 = LOOKUPVALUE ( staff[Actual Month (of List)], staff[Employee ID], staff[Employee ID], staff[Actual Month (of List)].[Month], staff[Actual Month (of List)].[Month], staff[Actual Month (of List)].[Year], staff[Actual Month (of List)].[Year] + 1 ) No Change/Left = IF ( staff[my + 12] <> BLANK (), "No change", "Left" )
Best regards,
Yuliana Gu
Hi @v-yulgu-msft,
Thanks, that works great! I didn't know you could use the same field as the search column name and value!
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
87 | |
85 | |
82 | |
65 | |
49 |
User | Count |
---|---|
137 | |
111 | |
101 | |
66 | |
65 |