Forum Discussion

Kolumam's avatar
Kolumam
Post Prodigy
7 years ago
Solved

Yesterday formula using datetime datatype in DAX

Hi All,

 

I need to compute yesterday with all the DateTime values but when I use the below-calculated column it returns just one value. I need all the date time values from yesterday.

Yesterday = IF('DATE'[Date] = (DATE(YEAR(NOW()), MONTH(NOW()), DAY(NOW()-1))), 1 , 0)

Please help.

  • hi, Kolumam 

    For the data type is datetime, so try this formula:

    New Yesterday = IF(DATE(YEAR('DATE'[Date]),  MONTH('Date'[Date]), DAY('Date'[Date]))= (DATE(YEAR(NOW()), MONTH(NOW()), DAY(NOW()-1))), 1 , 0)

    Result:

     

    Best Regards,

    Lin

3 Replies

  • MattAllington's avatar
    MattAllington
    Community Champion

    What are you going to do with this column after you create it?  It is unlikely that this is the best approach. What do you actually want to achieve?  

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Kolumam ,

    This is a way to do what you want, but as MattAllington said it might not be the best approach to your problem :

    Yesterday = IF(DATEADD('DATE'[Date],1,DAY)=TODAY(),1,0)

    Regards,

    Etienne

  • v-lili6-msft's avatar
    v-lili6-msft
    Community Support

    hi, Kolumam 

    For the data type is datetime, so try this formula:

    New Yesterday = IF(DATE(YEAR('DATE'[Date]),  MONTH('Date'[Date]), DAY('Date'[Date]))= (DATE(YEAR(NOW()), MONTH(NOW()), DAY(NOW()-1))), 1 , 0)

    Result:

     

    Best Regards,

    Lin