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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
babarbashir
New Member

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 entries added vs dec 2015, feb 2016 vs jan 2016 and so on in a single query.

 

Any help would be appreciated.

 

Regards,

 

YearMonthBranchEmp NameEmp No
201512B1Emp11
201512B2Emp22
201512B1Emp33
201512B2Emp44
201512B1Emp55
201512B1Emp66
20161B1Emp11
20161B2Emp22
20161B1Emp33
20161B2Emp44
20161B1Emp77
20161B1Emp66
20161B2Emp88
20162B1Emp11
20162B2Emp22
20162B1Emp33
20162B1Emp77
20162B1Emp66
20162B2Emp88
20162B1Emp99
20162B2Emp1010
20162B1Emp1111
20162B2Emp1212
20163B1Emp11
20163B2Emp22
20163B1Emp33
20163B1Emp77
20163B2Emp1010
20163B1Emp1111
20163B2Emp1212
20163B2Emp1313
20163B2Emp1414
20164B1Emp11
20164B2Emp22
20164B1Emp33
20164B1Emp77
20164B2Emp1010
20164B2Emp1414
1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

@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] )

Capture.PNG

 

 

Check more details in the attached pbix.

View solution in original post

1 REPLY 1
Eric_Zhang
Microsoft Employee
Microsoft Employee

@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] )

Capture.PNG

 

 

Check more details in the attached pbix.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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