Forum

What will be the DA...
 
Share:
Notifications
Clear all

What will be the DAX to find the date for last Saturday, if today is Saturday then today's date else last Saturday date


Posts: 15
Admin
Topic starter
(@sql-admin)
Eminent Member
Joined: 4 years ago

Description: "Learn how to find the date of the last Saturday using a simple DAX formula in Power BI. This guide provides a clear example with sample data, ensuring you can easily implement and understand the process. Ideal for Power BI users and data analysts seeking to enhance their DAX skills."

By following this guide, you can accurately calculate the last Saturday's date using DAX in Power BI, improving your data analysis and reporting capabilities.

To create a DAX formula that finds the date of the last Saturday, considering today is Saturday, the DAX can be written as follows:

LastSaturday =
IF (
WEEKDAY ( TODAY(), 2 ) = 6,
TODAY(),
TODAY() - WEEKDAY ( TODAY(), 2 ) + 5
)

Explanation:

  • TODAY(): Returns the current date.
  • WEEKDAY(TODAY(), 2): Returns the day of the week for the current date, with Monday as 1 and Sunday as 7. Therefore, Saturday is 6.
  • IF (WEEKDAY(TODAY(), 2) = 6, TODAY(), TODAY() - WEEKDAY(TODAY(), 2) + 5): This checks if today is Saturday. If true, it returns today's date; if false, it calculates the date of the last Saturday.

Example with Sample Data:

Let's say today is Friday, May 24, 2024.

  • TODAY(): May 24, 2024.
  • WEEKDAY(TODAY(), 2): 5 (because May 24, 2024, is a Friday).
  • TODAY() - WEEKDAY(TODAY(), 2) + 5: This calculates to May 24, 2024 - 5 + 5 = May 19, 2024, which is the previous Saturday.

If today were Saturday, May 25, 2024:

  • TODAY(): May 25, 2024.
  • WEEKDAY(TODAY(), 2): 6 (because May 25, 2024, is a Saturday).
  • The formula would then simply return TODAY(), which is May 25, 2024.

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: