Forum Discussion

sanchit's avatar
sanchit
Frequent Visitor
10 years ago
Solved

Expression error: The name 'SWITCH' wasn't recognized. Make sure it's spelled correctly.

 

Hi

I am trying to create a custom column on “Time Column” using Switch. Format of Time Column-"10:30:00 AM".

Desired Output : If Time is between “08:30:00 AM” and “10:30:00 AM" then “Peak Hours” else “Non Peak Hours”.

 

I have tried three different case :

  • SWITCH(TRUE(),

            AND([EventTime]>="06:30:00 AM", [EventTime]<="10:30:00 AM"), "Peak Hours",

            "Non Peak Hours"

            )

Error : Expression error: The name 'SWITCH' wasn't recognized.  Make sure it's spelled correctly

  •  SWITCH(TRUE(),

          [EventTime]>="06:30:00 AM" && [EventTime]<="10:30:00 AM"," PEAK HOURS",

          "NON PEAK HOURS"

          )

Error : Token Literal Expected

 I converted the Time column into text which changed the time format to “06:30”.

  • SWITCH(TRUE(),

         AND([#"EventTime - Copy"]>="06:30" ,[#"EventTime - Copy"]<="10:30")," PEAK HOURS",

        "NON PEAK HOURS"

         )

Error : Expression error: The name 'SWITCH' wasn't recognized.  Make sure it's spelled correctly

 

Same was the case when i tried with "IF". I am not sure if we can apply Switch case or If on Time Column.

 

Thanks in Advance.

  • Ahhhh, that's the problem. Switch is a DAX formula, but you are trying to use it in Power Query, which uses the Power Query Formula Language (PQL)

4 Replies

    • sanchit's avatar
      sanchit
      Frequent Visitor

      MattAllington  Yes , i used an equal sign , sorry did not copy that. And one more thing i am using Add Custom Column in Edit Queries.

      • MattAllington's avatar
        MattAllington
        Icon for Community Champion rankCommunity Champion

        Ahhhh, that's the problem. Switch is a DAX formula, but you are trying to use it in Power Query, which uses the Power Query Formula Language (PQL)