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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
kaka
Helper II
Helper II

Compare text with today()

I have a column called offer_date which has the followig value: Wednesday, 27 January, 2016 .

 

I am trying to compare this date with today's date in power bi DAX formula. 

 

 IF(DATEVALUE(offer_date) >= today(), "good job"

 

The problem is that the comparison is not happening for some reason. Does anyone know how to convert the text date into datetime and compare it with today() ? 

7 REPLIES 7
kaka
Helper II
Helper II

I was able to convert the initial text date to datetime. So from Wednesday, 27 February, 2017 to 02/27/2017 12:00:00 AM .  I went under the modeling tab and changed the data type from text to datetime. 

 

The only problem is that the foloowing is still not working: 

IF(DATEVALUE(offer_date) >= today(), "good job", "") 

 

Note that 02/27/17 is greater than today's date (02/20/17). So, it should be displaying "good job", but it's not. 

Sean
Community Champion
Community Champion

@kaka

This is happening because you have values (more like errors) that cannot be coverted to Date!!!

 

Blanks would not cause this - but text that cannot be coverted to a date say 4/1/

 

Comparison2.png

Comparison3.png

 

But I am not getting any such error. 

Hi @kaka,

 

Please try to click the Refresh button to refresh the data. Also update the desktop to latest version 2.43.4647.541.

 

You can also create a calculated column to return current date,

 

CurrentDate=Today()

 

Then create a calculated column:

 

IF(DATEVALUE(offer_date) >= CurrentDate, "good job", "")

 

If issue persists, would you please share the screenshots about the DAX and results for our analysis? If possible, please share the .pbix file.

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Sean
Community Champion
Community Champion

@kaka  The comparison is actually happening!

 

You are not seeing anything because you don't have anything in the [ResultIfFalse] part of the IF function

 

You need to reverse >= to <=

 

Comparison.png

 

EDIT: I'm assuming this is an Offer Made on Date so you want to it be less than today indicating that Offer has been made! Smiley Happy

Greg_Deckler
Super User
Super User

Go to the data model modeling tab in Power BI Desktop (or in Query Editor) and set the data type to "Date". Then you can do something like this in DAX (slightly different in M code):

 

Column = IF(DAY([Date]) = DAY(TODAY()) && MONTH([Date]) = MONTH(TODAY()) && YEAR([Date]) = YEAR(TODAY()),"good job","bad job")

 

 


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Phil_Seamark
Employee
Employee

What happens when you just create a column with the following code

 

new column = DATEVALUE('mytable'[offer_date])

secondly, do you round out your IF statement as follows?

 

new Column2 = if(DATEVALUE('myTable'[offer_Date]>=Today()),"Good Job","")

Oh and are you creating calculated columns as opposed to calculated Measures?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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