Forum Discussion
vincenardo
Helper I
4 years agoCompare 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!
- Anonymous4 years ago
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" )
2 Replies
- AnonymousNot 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" )- vincenardo
Helper I
Thank you, worked perfectly!