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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Bansi008
Helper II
Helper II

Need help in conditional statement.

Hi there,

In new custom column i wanted to write syntax as if column [sec_name] contains ABC corp 1 then populate ABC else NA. 

can someone please help me with syntax which will work in PowerBI transform view.

I tried :- IF [sec_name] contains "ABC Corp 1" then "ABC" else "NA"

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Bansi008 ,

Thank you for @anmolmalviya05 and @daircom answer , and I have other suggestions for you:

Below is my table:

vxiandatmsft_0-1721009873060.png

I try this expression:

= Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([sec_name], "ABC corp 1") then "ABC" else "NA")

The final output is shown in the following figure:

vxiandatmsft_1-1721009941082.png

If this doesn't work, please provide a screenshot of the error

Best Regards,

Xianda Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

In the last argument of the Text.Contains function, specify Comparer.OrdinalIgnoreCase to perform a non case sensitive search.  Read here - Text.Contains - PowerQuery M | Microsoft Learn


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Bansi008 ,

Thank you for @anmolmalviya05 and @daircom answer , and I have other suggestions for you:

Below is my table:

vxiandatmsft_0-1721009873060.png

I try this expression:

= Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([sec_name], "ABC corp 1") then "ABC" else "NA")

The final output is shown in the following figure:

vxiandatmsft_1-1721009941082.png

If this doesn't work, please provide a screenshot of the error

Best Regards,

Xianda Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Bansi008
Helper II
Helper II

Hi both,

unfortunately this solution doesn't work

anmolmalviya05
Solution Sage
Solution Sage

Hi @Bansi008, Hope you are doing good !

To create a custom column in Power BI's Power Query Editor that checks if the sec_name column contains the string "ABC Corp 1" and then populates "ABC" if true, or "NA" otherwise, you can use the following syntax in M language:

  1. Open Power Query Editor.
  2. Go to "Add Column" and select "Custom Column."
  3. Use the following formula: if Text.Contains([sec_name], "ABC Corp 1") then "ABC" else "NA"
  4. Click OK

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

 

daircom
Helper II
Helper II

Hi @Bansi008 ,

 

You need the functon Text.Contains (watch out, it is case sensitive).
So:

 

if Text.Contains([sec_name], "ABC Corp 1") then "ABC" else "NA"

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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