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
Anonymous
Not applicable

DAX weekend day calculation doesn't work for me

 

I am not able to have a simple dateadd for weekend day calculation work.   New to Power BI.  Can someone help?

The event date is pretty much simple daily date. and The weending2 is the calculated date based on event date.    Why the simple calculation won't work?

 

WeekEnding2 = FORMAT(DATEADD(datalake[last_event_date], (7 - (Weekday(datalake[last_event_date],2))), DAY), "YYYY-MM-DD")

 

 

Issue Screen shotIssue Screen shot

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

hi @Anonymous

 

try this:

 

Weekending = datalake[last_event__date]+(7-WEEKDAY(datalake[last_event__date];2))




Lima - Peru

View solution in original post

v-sihou-msft
Employee
Employee

@Anonymous

 

I can’t find any no syntax issue in your formula. But there is some limitations of DATEADD. The second one below should be the reason why your calculation won’t work for some dates.

  1. DATEADD only works with a contiguous date selection and raises an error otherwise.
  2. DATEADD only returns days existing in the date column received as first argument.
  3. When a corresponding day does not exist in the corresponding month after the shift operation, the result of DATEADD includes the last day of the corresponding month.
  4. When the selection includes the last day of a month, and the selection is more than one day, then the result of DATEADD includes all the days between the corresponding day in the shifted month and the end of the shifted month.

 

However you can get the expected results by creating a calculated column with following formula.

WeekEnding2 = 
FORMAT (
    datalake[last_event_date]
        + ( 7 - WEEKDAY ( datalake[last_event_date], 2 ) ),
    "YYYY-MM-DD"
)

26.png

 

Regards,

View solution in original post

3 REPLIES 3
v-sihou-msft
Employee
Employee

@Anonymous

 

I can’t find any no syntax issue in your formula. But there is some limitations of DATEADD. The second one below should be the reason why your calculation won’t work for some dates.

  1. DATEADD only works with a contiguous date selection and raises an error otherwise.
  2. DATEADD only returns days existing in the date column received as first argument.
  3. When a corresponding day does not exist in the corresponding month after the shift operation, the result of DATEADD includes the last day of the corresponding month.
  4. When the selection includes the last day of a month, and the selection is more than one day, then the result of DATEADD includes all the days between the corresponding day in the shifted month and the end of the shifted month.

 

However you can get the expected results by creating a calculated column with following formula.

WeekEnding2 = 
FORMAT (
    datalake[last_event_date]
        + ( 7 - WEEKDAY ( datalake[last_event_date], 2 ) ),
    "YYYY-MM-DD"
)

26.png

 

Regards,

Anonymous
Not applicable

Thanks @v-sihou-msft

Vvelarde
Community Champion
Community Champion

hi @Anonymous

 

try this:

 

Weekending = datalake[last_event__date]+(7-WEEKDAY(datalake[last_event__date];2))




Lima - Peru

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.