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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.