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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Jkrupski
Regular Visitor

Check if a date column is between 2 hard coded dates

Hello,

 

I am very new to power bi and dax, learning as I go.

 

I am trying to use an if statement that checks a date added column and compares it to 2 hard coded dates, if it is between the dates I want to display "P3" and if not then display "NA" in a new column. I have this code:

columnTest =

VAR dateAdded = FORMAT(table[column], "m/d/yyyy")

VAR P3Start = FORMAT(DATE(2025,3,29), "m/d/yyyy")
VAR P3End = FORMAT(DATE(2025,3,29), "m/d/yyyy")


RETURN


If(dateAdded <= P3End && dateAdded >= P3Start, "P3",
 "NA")
 
One date that is checking is 3/4/25, but it is constantly giving me the NA result where I want it to give the P3 result.
 
Any help would be greatly appreciated!
 
Thank you!
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Jkrupski Try:

columnTest =
VAR dateAdded = [column]
VAR P3Start = DATE(2025,3,29)
VAR P3End = DATE(2025,3,29)
RETURN
If(dateAdded <= P3End && dateAdded >= P3Start, "P3",
 "NA")

FORMAT turns dates into text and that is not a good way to compare dates.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Jkrupski ,

 

Thanks for the reply from Greg_Deckler .

 

There is something wrong with your start date and end date, they are both March 29, 2025, and P3 is returned only when the date is equal to March 29, 2025, and NA is returned for other dates.

vhuijieymsft_1-1741662130830.png

 

Modify your syntax, something like the code below:

columnTest = 
VAR dateAdd = 'Table'[column]
VAR P3Start = DATE(2025, 3, 4)
VAR P3End   = DATE(2025, 3, 29)
RETURN
    IF(
         dateAdd>= P3Start && dateAdd <= P3End,
        "P3",
        "NA"
    )

 

The final visual effect is shown below:

vhuijieymsft_0-1741662050777.png

 

The pbix file is attached.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

Greg_Deckler
Community Champion
Community Champion

@Jkrupski Try:

columnTest =
VAR dateAdded = [column]
VAR P3Start = DATE(2025,3,29)
VAR P3End = DATE(2025,3,29)
RETURN
If(dateAdded <= P3End && dateAdded >= P3Start, "P3",
 "NA")

FORMAT turns dates into text and that is not a good way to compare dates.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.