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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
CC852
Frequent Visitor

Help with Syntax Error

When I use the syntax below:

CC852_0-1699287016165.png

 

Week Ending =
DatesTable[Date]
    - MOD ( DatesTable[Date]1, 7 ) + 6
 

I get the error: 

The following syntax error occurred during parsing: Invalid token, Line 3, Offset 30, –.

How can I fix this? - thank you in advance!

1 ACCEPTED SOLUTION
audreygerred
Super User
Super User

If you are trying to create a calculated column for week ending date, try the below:

WeekEndingDate =
    'Date'[Date] + (7 - WEEKDAY('Date'[Date], 2))
 
This formula calculates the week ending date (assuming the week ends on Sunday) for each row in the table. The WEEKDAY function returns the day of the week corresponding to a date, with the day numbering starting from Monday (when the second argument is 2). The result is then subtracted from 7 to get the number of days until the end of the week, which is added to the original date to get the week ending date.
 
Below is the test I have completed:
audreygerred_0-1699288931165.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
audreygerred
Super User
Super User

If you are trying to create a calculated column for week ending date, try the below:

WeekEndingDate =
    'Date'[Date] + (7 - WEEKDAY('Date'[Date], 2))
 
This formula calculates the week ending date (assuming the week ends on Sunday) for each row in the table. The WEEKDAY function returns the day of the week corresponding to a date, with the day numbering starting from Monday (when the second argument is 2). The result is then subtracted from 7 to get the number of days until the end of the week, which is added to the original date to get the week ending date.
 
Below is the test I have completed:
audreygerred_0-1699288931165.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Wow, thank you so much!

I made an edit to your syntax (from 2 to 1) since I need weeks to end on a Saturday.

Week Ending =
    'DatesTable'[Date] + (7 - WEEKDAY('DatesTable'[Date], 1))



You're very welcome! Happy to help! Please mark as a solution so others are able to find it to help in the future. Have a great week!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.