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
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
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.