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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

DAX if statement syntax error

I am new to Power BI ... I am tyrying to insert a new custom column into a table in the Query Editor. The Column should extract data from an excisting column based on an "IF" Statement with an "CONTAINS" statement embeded in it. 

 

The syntax I've used is

=IF (CONTAINS([Content],"SHOWS"),"SHOWS",IF (OR([Content]="DRY","WATER"),"DRY","HC"))

 

I get a message stating that "No syntax errors have been detected" however when I "OK" the function I get a new message stating

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

 

Not sure what I'm doing wrong... any help?

1 ACCEPTED SOLUTION

@Anonymous Please note "Power Query" expressions are case sensitive.  "IF" not same as "if", please correct the all keywords in your expression.





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

Proud to be a PBI Community Champion




View solution in original post

6 REPLIES 6
PattemManohar
Community Champion
Community Champion

@Anonymous Please try this..

 

=IF (CONTAINS(TableName,[Content],"SHOWS"),"SHOWS",IF ([Content] IN {"DRY","WATER"},"DRY","HC"))

Note - CONTAINS will return TRUE if there is any row in the table that contains SHOWS in the Content field. Not sure whethere you want that behaviour or looking for searching in each row then try this

 

IF(SEARCH("SHOWS",[Content],1,0)>0,"SHOWS",IF(Test140[Content] IN {"DRY","WATER"},"DRY","HC"))

 





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

Proud to be a PBI Community Champion




Anonymous
Not applicable

I've tried both... and although there are no syntax error detected I still getr the message "Expression.Error: The name 'IF' wasn't recognised....."

 

Do I need to specify the Table name in the formula, seeing as this is a given

 

Capture.PNG

@Anonymous

 

looks like you're using Power Query and not DAX

 

try this:

 

= if Text.Contains([Conent],"SHOWS") then "SHOWS" else if List.Contains({"DRY","WATER"},[Content]) then "DRY" else "HC"

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

Yes I'm working in PowerQuery... (I thought this was the same)

 

I've tried several approaches nothing seems to work..

My Column conatins 12 unique types of entry (text), all those rows containing the words "SHOWS" should be returned as "SHOWS". Entries with "DRY" or "WATER" should return "DRY", all other entries should Return the value "HC"

 

Keep getting Syntax errors I don't understand... is the syntax case sensative, when should I use IF.. Then and Else rather than commas

 

 

(This is an Oil industry problem... in case you were wondering)

@Anonymous Please note "Power Query" expressions are case sensitive.  "IF" not same as "if", please correct the all keywords in your expression.





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

Proud to be a PBI Community Champion




Anonymous
Not applicable

SUCCESS... all in order....

Many thanks for your help... I've a long way to go on the learning curve

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.