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

Get 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

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
Microsoft Employee
Microsoft 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
Microsoft Employee
Microsoft 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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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