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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.