Forum Discussion

CaveOfWonders's avatar
CaveOfWonders
Helper IV
6 years ago

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

  • mahoneypat's avatar
    mahoneypat
    Microsoft 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

    • CaveOfWonders's avatar
      CaveOfWonders
      Helper 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"