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
PBI5851
Helper V
Helper V

If date is in previous month flag

Hello folks,

 I am trying to create a column to create a flag (FlagColumn) which is to have the below logic.

 

If any of the Date1 or Date2 happened in the previous month, then Previous. 

If no Dates then NoFlag

 

I tried using between start of month and EOmonth etc, but doesnt work.

Any recommendations please

 

PersonIdDate1Date2FlagColumn
A12311/1/23 CurrentMonth
A234  NoFlag
A4561/1/233/3/23Earlier
A5676/1/236/2/23Earlier
A6788/1/2310/1/23Previous
A78910/2/2310/4/23Previous
1 ACCEPTED SOLUTION
Anand24
Super User
Super User

Hi @PBI5851 ,
You can use the below DAX in a new measure:

Flag =
SWITCH(
    TRUE(),
    MAX('Table'[Date1]) = BLANK() && MAX('Table'[Date2]) = BLANK(), "No Flag",
    MONTH(MAX('Table'[Date1])) = MONTH(TODAY()) || MONTH(MAX('Table'[Date2])) = MONTH(TODAY()), "Current Month",
    MONTH(MAX('Table'[Date1])) = MONTH(TODAY()) - 1 || MONTH(MAX('Table'[Date2])) = MONTH(TODAY()) - 1, "Previous Month",
    "Earlier"
)
 
Result:
Anand24_0-1699563652068.png

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

View solution in original post

1 REPLY 1
Anand24
Super User
Super User

Hi @PBI5851 ,
You can use the below DAX in a new measure:

Flag =
SWITCH(
    TRUE(),
    MAX('Table'[Date1]) = BLANK() && MAX('Table'[Date2]) = BLANK(), "No Flag",
    MONTH(MAX('Table'[Date1])) = MONTH(TODAY()) || MONTH(MAX('Table'[Date2])) = MONTH(TODAY()), "Current Month",
    MONTH(MAX('Table'[Date1])) = MONTH(TODAY()) - 1 || MONTH(MAX('Table'[Date2])) = MONTH(TODAY()) - 1, "Previous Month",
    "Earlier"
)
 
Result:
Anand24_0-1699563652068.png

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

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.

Top Solution Authors