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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.