Forum Discussion
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:
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.
2 Replies
- Greg_DecklerCommunity 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.
- AnonymousNot 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.
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:
The pbix file is attached.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support TeamIf 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!