Forum Discussion

kaka's avatar
kaka
Icon for Helper II rankHelper II
9 years ago

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's avatar
    Sean
    Icon for Community Champion rankCommunity 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's avatar
    Phil_Seamark
    Icon for Microsoft Employee rankMicrosoft 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's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity 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")

     

     

  • 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's avatar
      Sean
      Icon for Community Champion rankCommunity 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/

       

       

      • kaka's avatar
        kaka
        Icon for Helper II rankHelper II

        But I am not getting any such error.