Forum Discussion
M Query Syntax help
I found the M code below online, but cannot get it to work. The code is supposed to allow you to get a week start date calculation
I'm getting the error:
An error occurred in the ‘’ query. Expression.Error: The name 'Week Start' wasn't recognized. Make sure it's spelled correctly.
Could someone please help me get this to work, I know it's probably something quite easy.
What do I need to change/add to get this to work?
6 Replies
- HennadiiHelper IV
It looks like you miss definition what is #"Week Start", equal sign is useless before let, and anfter in, I suppose should be Source as a return value.
Please refer to the link below to learn more about let/in syntax:
https://docs.microsoft.com/en-us/powerquery-m/expressions-values-and-let-expression
- mahoneypatMicrosoft Employee
The error is the reference to your previous step - #"Week Start". You need to reference your previous step. In your query, on the Add Column tab, add Custom Column and put the Date.ToText( ....) part in the box that comes up. Also make sure the column with date values is called [Date], otherwise change that too.
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
- CaveOfWondersHelper IV
Thank you for your reply Pat; I've added the code here to make it easier to edit as I haven't been able to get it to work sorry. There are no previous steps, this is a standalone column? Add Custom column wasn't coming up as an option? Sorry 🤔
let
Source = Table.AddColumn(#"Week Start", each Date.ToText(Date.StartOfWeek([Date], Day.Sunday),"MM/dd/yyyy"))
in
#"Week Start"- HennadiiHelper IV
CaveOfWonders , you mentioned you found this code somwhere online. Do you have a link?