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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
vincenardo
Helper I
Helper I

Compare Month and Year between two date fields

I have a table that has two dates for each record (TransDate & COCDate), I want to create a calculated column that will compare the Month and Year of 'TransDate' to the 'COCDate' and return BEFORE, IN or AFTER.

 

For Example;

1. TransDate = 12/1/2021 and COC Date = 12/4/2021 returns IN

2. TransDate = 12/1/2021 and COC Date = 11/1/2020 returns BEFORE

3. TransDate = 12/2/2021 and COC Date = 1/1/2022 returns AFTER

 

Suggestions are appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@vincenardo please try a Calculated Column with this DAX formula:

DateStatus = 
    SWITCH(TRUE(),
        DATEDIFF([TransDate], [COCDate], MONTH) = 0, "IN",
        DATEDIFF([TransDate], [COCDate], MONTH) < 0, "BEFORE",
        DATEDIFF([TransDate], [COCDate], MONTH) > 0, "AFTER"
    )

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@vincenardo please try a Calculated Column with this DAX formula:

DateStatus = 
    SWITCH(TRUE(),
        DATEDIFF([TransDate], [COCDate], MONTH) = 0, "IN",
        DATEDIFF([TransDate], [COCDate], MONTH) < 0, "BEFORE",
        DATEDIFF([TransDate], [COCDate], MONTH) > 0, "AFTER"
    )

Thank you, worked perfectly!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.