Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calculate last thursday date

Hello,

 

I want to get the date of the last thursday.

For example,

IF today=thursday

return today_date

ELSE

return last_thursday date

 

How could I do this?

 

Thank you in advance

 

 

  • Anonymous 

    Create the following measure to get the desired results:

    Date Measure = 
    var __day = FORMAT(TODAY(),"ddd") return
    IF(
        __day = "Thu",
        TODAY(),
        MAXX( FILTER( ADDCOLUMNS( CALENDAR(TODAY()-6,TODAY()-1) , "wDay" , WEEKDAY([Date],2) ), [wDay] = 4 ),[Date] )
    )

     



2 Replies

  • selimovd's avatar
    selimovd
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hey Anonymous ,

     

    from your syntax I guess you want to solve that in Power Query.

    You can check which day the date is with the function Date.DayOfWeek. The order starts with Sunday = 1, so Thursday is a 5.

    Then you can do the math and subtract it from the date.

     

    In DAX you can use the same approach with the WEEKDAY function.

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis
     
  • Anonymous 

    Create the following measure to get the desired results:

    Date Measure = 
    var __day = FORMAT(TODAY(),"ddd") return
    IF(
        __day = "Thu",
        TODAY(),
        MAXX( FILTER( ADDCOLUMNS( CALENDAR(TODAY()-6,TODAY()-1) , "wDay" , WEEKDAY([Date],2) ), [wDay] = 4 ),[Date] )
    )