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, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Archie_ZHANG
Frequent Visitor

Need help on calculate new joiner & leaver

Below is sample table I have, I need two measurement. 

First is New joiner, which needs "Current Month Status" = 1, and "Last Month Status"=0, like "Jane Doe".

Second is Leaver, which needs "Current Month Status" = 0, and "Last Month Status"=1 , like "John Smith".

But "Michael Chen" should neither count into New joiner or Leaver, because he is internal promotion.

 

 

Employee Name Job Title Status Amount

John SmithSoftware EngineerLast Month Status1
John SmithSoftware EngineerCurrent Month Status0
Jane DoeMarketing ManagerLast Month Status0
Jane DoeMarketing ManagerCurrent Month Status1
Michael ChenData Analyst 1Last Month Status1
Michael ChenData Analyst 1Current Month Status0
Michael ChenData Analyst 2Last Month Status0
Michael ChenData Analyst 2Current Month Status1
    
    
    
    
    
    
    
    
    
    
    
    
1 ACCEPTED SOLUTION
talespin
Solution Sage
Solution Sage

hi @Archie_ZHANG ,

 

There can be many ways to solve this. You have not covered all scenarios. What if employee is promoted and leaves and joins the company again. Please note the solution may not work properly under unknown scenarios. If you can share all of them, I can cover them.

 

The logic I have used to identify joiners and leavers is

Take max of Previous month status and Current month Status

PrevMth = 0 and CurrMth = 1 - joiners

PrevMth = 1 and CurrMth = 0 - Leavers

PrevMth = 1 and CurrMth = 1 - Ignore

 

 

Count of Joiners =
SUMX(
        ALL(TblStat[Employee Name]),
        VAR _EmpNme = [Employee Name]
        VAR _PrevMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Last Month Status")
        VAR _CurrMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Current Month Status")
        RETURN IF( _PrevMth = 0 && _CurrMth = 1, 1, 0)
)
 

 

Count of Leavers =
SUMX(
        ALL(TblStat[Employee Name]),
        VAR _EmpNme = [Employee Name]
        VAR _PrevMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Last Month Status")
        VAR _CurrMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Current Month Status")
        RETURN IF( _PrevMth = 1 && _CurrMth = 0, 1, 0)
)
 

talespin_0-1707644505357.png

 

View solution in original post

8 REPLIES 8
talespin
Solution Sage
Solution Sage

hi @Archie_ZHANG ,

 

There can be many ways to solve this. You have not covered all scenarios. What if employee is promoted and leaves and joins the company again. Please note the solution may not work properly under unknown scenarios. If you can share all of them, I can cover them.

 

The logic I have used to identify joiners and leavers is

Take max of Previous month status and Current month Status

PrevMth = 0 and CurrMth = 1 - joiners

PrevMth = 1 and CurrMth = 0 - Leavers

PrevMth = 1 and CurrMth = 1 - Ignore

 

 

Count of Joiners =
SUMX(
        ALL(TblStat[Employee Name]),
        VAR _EmpNme = [Employee Name]
        VAR _PrevMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Last Month Status")
        VAR _CurrMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Current Month Status")
        RETURN IF( _PrevMth = 0 && _CurrMth = 1, 1, 0)
)
 

 

Count of Leavers =
SUMX(
        ALL(TblStat[Employee Name]),
        VAR _EmpNme = [Employee Name]
        VAR _PrevMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Last Month Status")
        VAR _CurrMth = CALCULATE( MAX(TblStat[Status]), REMOVEFILTERS(TblStat), TblStat[Employee Name] = _EmpNme, TblStat[Check] = "Current Month Status")
        RETURN IF( _PrevMth = 1 && _CurrMth = 0, 1, 0)
)
 

talespin_0-1707644505357.png

 

@talespin Thanks so much for your help. It works well after slight update. 

 

There is an advanced question, not sure can you help to check. Current "Leaver" just count current month & prior month exit employees, do you have any idea on how to get TTM (tailing 12 months, i.e. Feb-23 to Jan-24) leavers and YTD leavers (Jul-23 to Jan-24, Jul is start month of our company). Thanks.

This is HC table raw data: https://drive.google.com/file/d/1PMpP5xwBp6IqtXnrkc9ODEgplfBnw6Sf/view?usp=sharing

 

**"Calendar" table is time-series table in my PBI working file, which can support Time function.

 

//this is "leavers" modified from your solution

Leavers =
VAR _prior ='Universal'[Prior] //input 12 in universal variable
VAR _current='Universal'[Current] //input 01 in universal variable
RETURN
SUMX (
    DISTINCT ( 'HC EPM'[EE ID] ),
    VAR _id = 'HC EPM'[EE ID]
    VAR _PrevMth =
        CALCULATE (
            MAX ( 'HC EPM'[Amount] ),
            REMOVEFILTERS ( 'HC EPM' ),
            'HC EPM'[EE ID] = _id,
            'HC EPM'[Scenario] = "Current Fcst",
            'Calendar'[FiscalYear]="FY24",
            'Calendar'[Monthnumber]=_prior
        )
    VAR _CurrMth =
        CALCULATE (
            MAX ( 'HC EPM'[Amount] ),
            REMOVEFILTERS ( 'HC EPM' ),
            'HC EPM'[EE ID] = _id,
            'HC EPM'[Scenario] = "Current Fcst",
                        'Calendar'[FiscalYear]="FY24",
            'Calendar'[Monthnumber]=_current
        )
    RETURN
        IF ( _PrevMth = 1 && _CurrMth = 0, -1, 0 )
)

hi @Archie_ZHANG 

 

Please help understand raw data.

 

1. For EE_ID = E222446, I see two records for each month with different job title, one with Amount 1 and 0.

2. What is the significance of "column "Scenario".

 

1. Employee with "0" stands for this guy is not in this role,but recoreded due to he on this role before. "1" stands for the role of the employee right now in-seat. For the EE_ID E222446, can understand FY23 whole year, this employee on "SQ_LEARNING ENGAGEMENT AE 4_SQ56014", but he moves to "SQ_LEARNING AE 4_SQ56014" from Jul-24. I also attach a screenshot of original ERP pulling for your better understanding. 

Archie_ZHANG_0-1707728992426.png

 


2. Scenario is an indicator to distinguish forecast cycle, Current Fcst is the last forecast case finance team process, Plan is planning case finance team doing at the beginning of fiscal year. For easier work, you can filter out "plan" case.

hi @Archie_ZHANG 

 

Sorry, I do not understand the data. I have lot of questions.

What about this E151492 & E237903. Please explain.

@talespin Super thanks to your help. E151492, when planning we assume this employee will in-seat across whole year, so "Scenario - Plan" E151492 all month is 1, but this employee resigned at Nov. So from Dec-24 under "Current Fcst", it shows 0 from Dec. E237903, this employee resigned at the end of FY23 (Jun-23), so others month are 0.

If the raw data is too troublesome to understand, you can refer to our original table, can imagine "TblStat[Check]" become three opinions, like, "Current month", "Last Month", and "Two month ago". Then trying to get the rolling leavers number for each month. 

hi @Archie_ZHANG 

 

Used two measures,

Leavers  - It will return Leavers for all months.

Rolling 12Mths Leavers - For every month it will Sum for last 12 month.

To show only last 12 months data in Table and Column chart, i have also applied filter Calendar[Date] on visual(Screenshot). 

Also sharing data i used.

The logic I have used to identify joiners and leavers is

Take max of Previous month status and Current month Status

PrevMth = 1 and CurrMth = 0 - Leavers

PrevMth = 1 and CurrMth = 1 - Ignore

 

 
Leavers =
SUMX(
            SUMMARIZE(FactEmployee, 'CALENDAR'[YEAR], 'CALENDAR'[MonthNo], FactEmployee[Employee Name]),
            VAR _Year =  [YEAR]
            VAR _Mth = [MonthNo]
            VAR _Dt = DATE(_Year, _Mth, 1)
            VAR _CurrMth = CALCULATE( MAX(FactEmployee[Status]), REMOVEFILTERS('CALENDAR'), FILTER( ALL('CALENDAR'[Date]), 'CALENDAR'[Date] = _Dt) )
            VAR _PrevMth = CALCULATE( MAX(FactEmployee[Status]), REMOVEFILTERS('CALENDAR'), FILTER( ALL('CALENDAR'[Date]), 'CALENDAR'[Date] = EDATE(_Dt, -1)) )
            RETURN IF( _PrevMth = 1 && _CurrMth = 0, 1, 0)
)
 
Rolling 12Mths Leavers =
VAR _Year =  MAX('CALENDAR'[YEAR])
VAR _Mth = MAX('CALENDAR'[MonthNo])
VAR _CurrentDate = DATE(_Year, _Mth, 1)
VAR _T12Date = EOMONTH(_CurrentDate, -12)+1

RETURN CALCULATE([Leavers], 'CALENDAR'[Date] >= _T12Date && 'CALENDAR'[Date] <= _CurrentDate)
 
talespin_0-1707797599077.pngtalespin_1-1707797676949.png

 

Employee NameJob TitleDtCheckStatus

John SmithSoftware Engineer01 October 20220
John SmithSoftware Engineer01 November 20220
John SmithSoftware Engineer01 December 20220
John SmithSoftware Engineer01 January 20230
John SmithSoftware Engineer01 February 20230
John SmithSoftware Engineer01 March 20230
John SmithSoftware Engineer01 April 20230
John SmithSoftware Engineer01 May 20230
John SmithSoftware Engineer01 June 20230
John SmithSoftware Engineer01 July 20231
John SmithSoftware Engineer01 August 20231
John SmithSoftware Engineer01 September 20231
John SmithSoftware Engineer01 October 20231
John SmithSoftware Engineer01 November 20231
John SmithSoftware Engineer01 December 20231
John SmithSoftware Engineer01 January 20241
John SmithSoftware Engineer01 February 20241
Jane DoeMarketing Manager01 October 20221
Jane DoeMarketing Manager01 November 20221
Jane DoeMarketing Manager01 December 20221
Jane DoeMarketing Manager01 January 20231
Jane DoeMarketing Manager01 February 20231
Jane DoeMarketing Manager01 March 20231
Jane DoeMarketing Manager01 April 20231
Jane DoeMarketing Manager01 May 20231
Jane DoeMarketing Manager01 June 20231
Jane DoeMarketing Manager01 July 20231
Jane DoeMarketing Manager01 August 20230
Jane DoeMarketing Manager01 September 20230
Jane DoeMarketing Manager01 October 20230
Jane DoeMarketing Manager01 November 20230
Jane DoeMarketing Manager01 December 20230
Jane DoeMarketing Manager01 January 20240
Jane DoeMarketing Manager01 February 20240
Michael ChenData Analyst 101 October 20221
Michael ChenData Analyst 101 November 20221
Michael ChenData Analyst 101 December 20221
Michael ChenData Analyst 101 January 20231
Michael ChenData Analyst 101 February 20231
Michael ChenData Analyst 101 March 20231
Michael ChenData Analyst 101 April 20231
Michael ChenData Analyst 101 May 20231
Michael ChenData Analyst 101 June 20231
Michael ChenData Analyst 101 July 20231
Michael ChenData Analyst 101 August 20231
Michael ChenData Analyst 101 September 20230
Michael ChenData Analyst 101 October 20230
Michael ChenData Analyst 101 November 20230
Michael ChenData Analyst 101 December 20230
Michael ChenData Analyst 101 January 20240
Michael ChenData Analyst 101 February 20240
Michael ChenData Analyst 201 October 20220
Michael ChenData Analyst 201 November 20220
Michael ChenData Analyst 201 December 20220
Michael ChenData Analyst 201 January 20230
Michael ChenData Analyst 201 February 20230
Michael ChenData Analyst 201 March 20230
Michael ChenData Analyst 201 April 20230
Michael ChenData Analyst 201 May 20230
Michael ChenData Analyst 201 June 20230
Michael ChenData Analyst 201 July 20230
Michael ChenData Analyst 201 August 20230
Michael ChenData Analyst 201 September 20231
Michael ChenData Analyst 201 October 20231
Michael ChenData Analyst 201 November 20231
Michael ChenData Analyst 201 December 20231
Michael ChenData Analyst 201 January 20241
Michael ChenData Analyst 201 February 20241
MarkMarketing Manager01 October 20221
MarkMarketing Manager01 November 20221
MarkMarketing Manager01 December 20221
MarkMarketing Manager01 January 20231
MarkMarketing Manager01 February 20231
MarkMarketing Manager01 March 20231
MarkMarketing Manager01 April 20231
MarkMarketing Manager01 May 20231
MarkMarketing Manager01 June 20231
MarkMarketing Manager01 July 20231
MarkMarketing Manager01 August 20231
MarkMarketing Manager01 September 20231
MarkMarketing Manager01 October 20231
MarkMarketing Manager01 November 20230
MarkMarketing Manager01 December 20230
MarkMarketing Manager01 January 20240
MarkMarketing Manager01 February 20240
RoseSoftware Engineer01 October 20220
RoseSoftware Engineer01 November 20220
RoseSoftware Engineer01 December 20220
RoseSoftware Engineer01 January 20230
RoseSoftware Engineer01 February 20230
RoseSoftware Engineer01 March 20230
RoseSoftware Engineer01 April 20230
RoseSoftware Engineer01 May 20230
RoseSoftware Engineer01 June 20230
RoseSoftware Engineer01 July 20230
RoseSoftware Engineer01 August 20230
RoseSoftware Engineer01 September 20230
RoseSoftware Engineer01 October 20230
RoseSoftware Engineer01 November 20230
RoseSoftware Engineer01 December 20231
RoseSoftware Engineer01 January 20241
RoseSoftware Engineer01 February 20241
LillyData Analyst 101 October 20220
LillyData Analyst 101 November 20220
LillyData Analyst 101 December 20220
LillyData Analyst 101 January 20230
LillyData Analyst 101 February 20231
LillyData Analyst 101 March 20231
LillyData Analyst 101 April 20231
LillyData Analyst 101 May 20231
LillyData Analyst 101 June 20231
LillyData Analyst 101 July 20231
LillyData Analyst 101 August 20230
LillyData Analyst 101 September 20230
LillyData Analyst 101 October 20230
LillyData Analyst 101 November 20230
LillyData Analyst 101 December 20230
LillyData Analyst 101 January 20240
LillyData Analyst 101 February 20240

 

hi @Archie_ZHANG ,

 

You're welcome. Will check and let you know.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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