Forum Discussion

babarbashir's avatar
babarbashir
New Member
9 years ago
Solved

list difference from previous month data

DAXI have a month wise employee data (sample below) and I want to calculate the leavers (removed) and joiners(added) by month.    e.g. Jan 2016, I want to know many entries removed and how many new...
  • Eric_Zhang's avatar
    9 years ago

    babarbashir

     

    In my opinion, you will need some calculcated columns, a calendar table and some measures in this case.

     

    calculated columns

    Date = DATE(Entries[Year],Entries[Month],1)

    if last month's entry exists =
    SWITCH (
        TRUE (),
        CALCULATE (
            VALUES ( Entries[Emp No] ),
            FILTER (
                ALL ( Entries ),
                EARLIER ( Entries[Branch] ) = Entries[Branch]
                    && EARLIER ( Entries[Emp No] ) = Entries[Emp No]
                    && EARLIER ( Entries[Date] ) = DATEADD ( Entries[Date], +1, MONTH )
            )
        )
            = BLANK (), "N",
        "Y"
    )

    Measures

     

    new entries = CALCULATE(COUNTROWS(Entries),Entries[if last month's entry exists]="N")
    
    removed entires =
    COUNTROWS (
        FILTER (
            ALL ( Entries ),
            MAX ( 'Calendar'[Date] ) = DATEADD ( Entries[Date], +1, MONTH )
        )
    ) // last month's entries
        - ( COUNTROWS ( Entries ) - [new entries] )

     

     

    Check more details in the attached pbix.