cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

If then else syntax error

Hi,

I have a column called 'Sentiment' with numbers between 0 and 1. 

I want to add a new column based on the condition as follows:

[Sentiment] <0.5 then "Negative"

[Sentiment] =0.5 then "Neutral"

[Sentiment] >0.5 then "Positive"

I know you can add a conditional column in PowerBI. 

But at the beginning I wrote a query like this:

 

If [Sentiment]< 0.5 then "Negative"
else
If [Sentiment] = 0.5 then "Neutral"
else
If [sentiment] >0.5 then "Positive"
else NULL

 

There is an error message says Token Eof expected. 

What should be the correct query for this?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: If then else syntax error

@Iyao - Don't capitalize your if's Also, I don't think you want NULL capitalized either. M is picky about these things.


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Highlighted
Super User IV
Super User IV

Re: If then else syntax error

@Iyao - Don't capitalize your if's Also, I don't think you want NULL capitalized either. M is picky about these things.


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Highlighted
New Member

Re: If then else syntax error

It works. Thank you

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021