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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Employee
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
Employee
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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