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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Query Editor If Statement

I have tried both the Conditional Column and the Custom column but have not been able to get this to work. 

 

I need a field called Workmanship, IF the value in the column English is Scratches, I want Workmanship to = No. For all other values, I want it to = Yes. 

 

Please help. 

 

Capture.PNG

1 ACCEPTED SOLUTION

You don't have to write the code. In Query Editor, right-click the column in question and then go to Transform | Trim. Then repeat for Transform | Clean. These two steps should be BEFORE your conditional column.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

The expression you wrote for custom column works fine in my test. There might existing some non-printable characters in [English] field. Please try smoupre's suggestion to remove those non-printable characters and try again.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
RohithGn
Helper I
Helper I

You could also create a custom column using a search function within IF to get what you want

 

Workmanship = If(SEARCH("Scratches",Table1[English],1,0)>0,"No","Yes")

 

But this will include all the rows where ever the word Scratches available to No

 

Hope this helps

Greg_Deckler
Super User
Super User

I suspect that you need to add a Trim step and maybe a clean step for your English column, See my example here:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bYuxDsIwDAV/5Skz38EEE2PUwTFWYxE5UexW9O9B6gjj3elyTlcqUxnbqL15yDygjl19o9YOWA8Qs4yg0gTd4EJfZU8U4ldaLjk9eFJwFT8pSM3/hFvvLvCYautp7uIV8mZx112w0vj5lg8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Engrish = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Engrish", type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Engrish", Text.Trim, type text}}),
    #"Cleaned Text" = Table.TransformColumns(#"Trimmed Text",{{"Engrish", Text.Clean, type text}}),
    #"Added Conditional Column" = Table.AddColumn(#"Cleaned Text", "Custom", each if [Engrish] = "Scratches" then "No" else "Yes")
in
    #"Added Conditional Column"


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you for the response. This looks a little scary to me. 🙂

 

Would I add this in the actual formula of the added column? 

You don't have to write the code. In Query Editor, right-click the column in question and then go to Transform | Trim. Then repeat for Transform | Clean. These two steps should be BEFORE your conditional column.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you so much! This worked perfectly!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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