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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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
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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.