cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sanchit Frequent Visitor
Frequent Visitor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

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

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)



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

4 REPLIES 4

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

Maybe this is a silly question, but are you putting an equal sign first?  It is not in your formulas. Also, your test seems to be a text test, but you say it is a time column.   Try using the time function in place of the text representation of the time. https://msdn.microsoft.com/en-us/library/ee634564.aspx



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
sanchit Frequent Visitor
Frequent Visitor

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

@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.

Highlighted

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

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)



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

sanchit Frequent Visitor
Frequent Visitor

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

@MattAllington Oh... I did not know that. Thanks for your help. I added a new column in Table Format it worked 🙂

This is what i used :

Column = SWITCH(TRUE(),
AND([EventTime]>=TIMEVALUE("09:30:00 AM"), [EventTime]<=TIMEVALUE("10:00:00 AM")), "Peak Hours",
"Non Peak Hours"
)

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors