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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
lmfernandez
Frequent Visitor

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

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@lmfernandez 

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] )
)

Fowmy_0-1621887981075.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@lmfernandez 

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] )
)

Fowmy_0-1621887981075.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

selimovd
Super User
Super User

Hey @lmfernandez ,

 

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
 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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