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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
willpage
Helper II
Helper II

Help with Week Ending Date DAX Column

Hello,

 

Hopefully this is an easy one. I have the following column in my date table, which I use to calculate the last day of the week for each row:

End of Week = 
VAR DayNumberOfWeek = WEEKDAY(LASTDATE('Date Table'[Date]),3)
RETURN
DATEADD(
    'Date Table'[Date],
    6 - DayNumberOfWeek,
    DAY)

 This works fine, except the current week:

willpage_1-1614721756798.png

 

I can't figure out how the DAX code above results in a blank value for this column. In this example, I would have thought that the Date (Monday 1st march) would have 6 - the day number (0) = 6 days added, resulting in Sunday 7th March.

However, the value is blank.

 

Why is this, and how can I make it so this value is not blank?

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula should work

='Date Table'[Date] + (7 - WEEKDAY('Date Table'[Date],2))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula should work

='Date Table'[Date] + (7 - WEEKDAY('Date Table'[Date],2))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Perfect, thanks. Much simpler than my previous formula, which I adapted from forumula to get week start date, that I found in a blog post somehere.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
HotChilli
Super User
Super User

Does the date table end before 7th March? The results from DATEADD have to be in the dates column, so to solve it you can construct the date without using dateadd or extend the date table  

@HotChilli  Thanks for your response.

 

The date range of the date table is taken from the earliest and latest dates in a date column from a fact table of timesheet data. So as it is now, the last date in the date table will never be later than the current day.

 

I can easily edit the date table in PQ to go a bit further into the future, but I would be interested to know how I could do a similar calculation to achieve the desired result without needing to do that (out of curiosity)?

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.