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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Comparing a month to it's relative previous month in a table

I have an "Employee" table similar to the following:

 

Employee.PNG

 

I need to take this table and check a month with it's relative previous month to see which employees existed in the previous month and which employees are new.  This helps me decide which employee should be marked as a hire and which should be marked as an employee that left the company.

 

For example, with the "Employee" table above, the results should look somewhat like this "Employee Status" table:

 

Employee Status.PNG

 

February compares it's data with January and notices that Employee ID 1 doesn't exist in February any more, so we need to mark it as "Left," while Employee ID 4 exists in February and doesn't in January, so Employee ID 4 would be a "Hire."  

 

This continues in March with Employee ID 3 that doesn't exist in March but did in February, so that employee is marked as "Left," and Employee ID 5 is new for March and did not exist in the previous month, so Employee ID 5 is a new "Hire."

 

Is it possible to create such an "Employee Status" table if all I have is the "Employee" table above?

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may add calculated columns as follows.

Column =
VAR e = Employee[Employee ID]
VAR m = Employee[Month]
RETURN
    IF (
        m > MIN ( Employee[Month] )
            && NOT (
                CONTAINS (
                    Employee,
                    Employee[Employee ID], e,
                    Employee[Month], DATE ( YEAR ( m ), MONTH ( m ) - 1, 1 )
                )
            ),
        "Hire"
    )
Column 2 =
VAR e = Employee[Employee ID]
VAR m = Employee[Month]
RETURN
    IF (
        m < MAX ( Employee[Month] )
            && NOT (
                CONTAINS (
                    Employee,
                    Employee[Employee ID], e,
                    Employee[Month], DATE ( YEAR ( m ), MONTH ( m ) + 1, 1 )
                )
            ),
        "Left"
    )
Community Support Team _ Sam Zha
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-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may add calculated columns as follows.

Column =
VAR e = Employee[Employee ID]
VAR m = Employee[Month]
RETURN
    IF (
        m > MIN ( Employee[Month] )
            && NOT (
                CONTAINS (
                    Employee,
                    Employee[Employee ID], e,
                    Employee[Month], DATE ( YEAR ( m ), MONTH ( m ) - 1, 1 )
                )
            ),
        "Hire"
    )
Column 2 =
VAR e = Employee[Employee ID]
VAR m = Employee[Month]
RETURN
    IF (
        m < MAX ( Employee[Month] )
            && NOT (
                CONTAINS (
                    Employee,
                    Employee[Employee ID], e,
                    Employee[Month], DATE ( YEAR ( m ), MONTH ( m ) + 1, 1 )
                )
            ),
        "Left"
    )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Those calculated columns definitely gave me the basis for creating my analysis.  I appreciate the help!  Thank you!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.