Forum Discussion
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
- Sean
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 <=
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! :smileyhappy:
- Phil_Seamark
Microsoft 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?
- Greg_Deckler
Community Champion
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")
- kaka
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.