Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

Switching between row and table context in DAX/Calculating 12-month staff attrition measure

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!

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

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" )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

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" )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

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!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.