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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
nickashwell
New Member

Token Comma Expected - In Column name?

Hi,

I am trying to generate a calculated colomn for reporting purposes and after being pointed towards SWITCH rather than IF functions I am now getting the below error in a custom column?

 

Clearly there should never be a comma in that name?

 

Any help would be appreciated

 

Thanks

nickashwell_0-1635326825945.png

 

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @nickashwell ,

 

it looks like there are two things mixed.

You can add a calculated column in Power BI. There the language is DAX.

Or you can add a column in Power Query. There the language is M.

 

In your screenshot you add a new column in Power Query, so the language is M. But the SWITCH function is DAX, so it would only work in a calculated column in Power BI.

 

If you want to add a column in Power Query, you have to use the M language. Sadly M doesn't have a SWITCH function, so you would have to add it as if and else. Check the syntax here:

M Language Conditionals - PowerQuery M | Microsoft Docs

Or as an example for the syntax:

if [my Column] >= 10 and [other Column] <= 100 
then "Category 1"
else if [my Column] >= 20 and [other Column] <= 200 
then  "Category 2"
else  "Category 3"

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

2 REPLIES 2
selimovd
Super User
Super User

Hey @nickashwell ,

 

it looks like there are two things mixed.

You can add a calculated column in Power BI. There the language is DAX.

Or you can add a column in Power Query. There the language is M.

 

In your screenshot you add a new column in Power Query, so the language is M. But the SWITCH function is DAX, so it would only work in a calculated column in Power BI.

 

If you want to add a column in Power Query, you have to use the M language. Sadly M doesn't have a SWITCH function, so you would have to add it as if and else. Check the syntax here:

M Language Conditionals - PowerQuery M | Microsoft Docs

Or as an example for the syntax:

if [my Column] >= 10 and [other Column] <= 100 
then "Category 1"
else if [my Column] >= 20 and [other Column] <= 200 
then  "Category 2"
else  "Category 3"

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
Greg_Deckler
Super User
Super User

@nickashwell SWITCH is a DAX function, not a power query M function. Unfortunately, there is no case or switch statement in power query.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.