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

I want to create 2 virtual tables using Date Filters and compare the changes in 2 tables

Hi All,

I have data with 6 columns like Date, Name, Email ID, Job Title, Department and Location.

 

image 1.JPG

I want to have 2 Date filters which will extract tables based on the two date filters.

Example show in Images below

Image 2.JPG

So I need to compare these two tables and want output in a list like

People who joined the company:

1) Sarath Kumar

 

People who left the company:

1) Anand Rajput

 

People whose Job title changed:

1) Bijoy Jha

2) Dinesh Singh

3) Raj Bose

 

 

Is this possible to handle such a situation in DAX?

Please help

 

 

 

Thanks,

Vrushab 

 

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

Hi @vrushabjain510 ,

 

Please follow these steps:

1. Add a Month table(for example):

Month =
DISTINCT (
    SELECTCOLUMNS (
        CALENDAR ( "2020/1/1", "2020/12/1" ),
        "MonthNumber", MONTH ( [Date] ),
        "Month", FORMAT ( [Date], "MMMM" )
    )
)

2.3.4.1.PNG

2. Add a Name table:

Name =
DISTINCT ( 'Table'[Name] )

2.3.4.2.PNG

3. Create measures based on selected two months:

first =
CALCULATE (
    MAX ( 'Table'[Job Title] ),
    FILTER (
        'Table',
        MONTH ( [Date] ) = MIN ( 'Month'[MonthNumber] )
            && 'Table'[Name] = MAX ( 'Name'[Name] )
    )
)
second =
CALCULATE (
    MAX ( 'Table'[Job Title] ),
    FILTER (
        'Table',
        MONTH ( [Date] ) = MAX ( 'Month'[MonthNumber] )
            && 'Table'[Name] = MAX ( 'Name'[Name] )
    )
)

4. Compare [first] and [second]

Measure =
IF (
    [first] = BLANK ()
        && [second] <> BLANK (),
    " Joined",
    IF (
        [first] <> BLANK ()
            && [second] = BLANK (),
        "Left",
        IF (
            [first] <> BLANK ()
                && [second] <> BLANK ()
                && [first] <> [second],
            "Job title changed"
        )
    )
)

 

The final output is shown below:
2.3.4.3.gif

 

Please take a look at the pbix file here.

 

Best Regards,
Eyelyn Qin
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

5 REPLIES 5
v-eqin-msft
Community Support
Community Support

Hi @vrushabjain510 ,

 

Please follow these steps:

1. Add a Month table(for example):

Month =
DISTINCT (
    SELECTCOLUMNS (
        CALENDAR ( "2020/1/1", "2020/12/1" ),
        "MonthNumber", MONTH ( [Date] ),
        "Month", FORMAT ( [Date], "MMMM" )
    )
)

2.3.4.1.PNG

2. Add a Name table:

Name =
DISTINCT ( 'Table'[Name] )

2.3.4.2.PNG

3. Create measures based on selected two months:

first =
CALCULATE (
    MAX ( 'Table'[Job Title] ),
    FILTER (
        'Table',
        MONTH ( [Date] ) = MIN ( 'Month'[MonthNumber] )
            && 'Table'[Name] = MAX ( 'Name'[Name] )
    )
)
second =
CALCULATE (
    MAX ( 'Table'[Job Title] ),
    FILTER (
        'Table',
        MONTH ( [Date] ) = MAX ( 'Month'[MonthNumber] )
            && 'Table'[Name] = MAX ( 'Name'[Name] )
    )
)

4. Compare [first] and [second]

Measure =
IF (
    [first] = BLANK ()
        && [second] <> BLANK (),
    " Joined",
    IF (
        [first] <> BLANK ()
            && [second] = BLANK (),
        "Left",
        IF (
            [first] <> BLANK ()
                && [second] <> BLANK ()
                && [first] <> [second],
            "Job title changed"
        )
    )
)

 

The final output is shown below:
2.3.4.3.gif

 

Please take a look at the pbix file here.

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-eqin-msftThis works perfectly. 
Thank you so much!

Hi @vrushabjain510 

 

Glad you found it helpful.😀

 

Best Regards,
Eyelyn Qin

Hi Amit @amitchandak , Thanks for the response. I have only one Date column. I have duplicated the same date filter and one date filter interacts with 1 table only (interaction with other table is off). 

 

My task is to compare the two produced table and find out who left the company, who joined the company and who changed their job title.

 

I hope you understood my requirement.

 

 

Thanks,

Vrushab Jain

amitchandak
Super User
Super User

@vrushabjain510 , how do we know the join date, termination date, or change department date? If you have two/ three dates, refer to his solution

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

Now the same date with two different filters on two tables. Use interactions. First filter should only interact with first table and second should interact with 2 tables

https://docs.microsoft.com/en-us/power-bi/create-reports/service-reports-visual-interactions

 

or have two date tables

example -https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

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.