How to Add Column If Contains in Power Query Power BI

When working with Power BI, I need to check if a column contains a specific word or value and then create a new column based on that. At first, I struggled with this because there are many different “contains” scenarios in Power Query. After working on e-commerce dashboard projects, I learned some easy, reliable ways to do so.

In this tutorial, I will show how to add a column in Power Query. Also, I will cover the following topic:

  • How to use Power Query M Code to Add a Column If Contains
  • Multiple Keywords Using IF Contains in Power Query
  • Add Column If Contains Number / Special Text in Power BI Power Query
  • Add Column If Contains in Another Column (Power Query)
  • Add Column If Column Contains Blank or Null in Power BI

Add Column If Contains in Power Query in Power BI

For this example, let’s use a simple Excel table named Orders.

Add Column If Contains in Power Query

Now I want to add a new column in Power Query that checks whether ProductName contains “Apple”, then marks it as “Apple Product”; otherwise, it marks it as “Other Brand.”

To do this, follow the steps below:

  1. In Power BI Desktop, open Power Query Editor. In the Queries pane, select the Orders table.
  2. Go to the Add Column tab. Click on Custom Column.
Create New Column with If Text Contains parameters
  1. A pop-up will open. Enter the following details:
    • New column name: Product Category
    • Custom column formula:
if Text.Contains([Product Name], "Apple") then "Apple Product" else "Other Brand"
add column if contains in power query in power bi
  1. You will now see a new column named Product Category added to your table.
how to Add Column If Contains in Power Query in Power BI

Finally, click Close & Apply to load the updated data back into Power BI.

Add a Column If Contains Using Power Query M Code

Sometimes you may want to write the M code directly instead of using the Custom Column UI. This gives you more control and is useful when working with complex logic.

Here I will use the same example.

  1. In Power Query Editor, select the Orders table. Go to the View tab and click Advanced Editor.
Add a Column If Contains Using Power Query M Code
  1. In the Advanced Editor, you will see the existing M code for your query.
Add a Column If Contains Using Power Query M Code in power BI
  1. Add the following line before the last line (just before in Source or the final output step):
#"Added Custom" = Table.AddColumn(Source, "Product Category", each if Text.Contains([Product Name], "Apple") then "Apple Product" else "Other Brand")
  1. Make sure to replace Source with the name of the previous step, if different. Click Done.
Power BI Add a Column If Contains Using Power Query M Code

You will now see the Product Category column created using M code.

Add a Column If Contains in Power Query M Code

Multiple Keywords Using IF Contains in Power Query

Sometimes you want to check whether a text contains any one of multiple keywords.
For example, if a product name includes Gold, Premium, or Exclusive, I want to categorize it as High Tier; otherwise, Standard.

For this example, I am using the products table. Check the screenshot below:

multiple keywords in one column using Power Query
  1. Open Power Query Editor -> Go to the Add Column tab. Click Custom Column.
  2. In the formula box, write a condition like:
if Text.Contains([Product Name], "Gold") 
   or Text.Contains([Product Name], "Premium") 
   or Text.Contains([Product Name], "Exclusive") 
then "High Tier" 
else "Standard"
Keyword Search in Multiple Columns with Power Query
  1. Then click on OK. After that, you can see the column in the Power Query editor.
Multiple Keywords Using IF Contains using Power Query in Power BI

If you want this using M code, you can use the code below:

= Table.AddColumn(Source, "Product Tier", each 
    if Text.Contains([Product Name], "Gold") 
       or Text.Contains([Product Name], "Premium") 
       or Text.Contains([Product Name], "Exclusive") 
    then "High Tier" 
    else "Standard")

Add Column If Contains Number / Special Text in Power Query

Sometimes text fields include numbers or special text patterns. For example, an Employee Code column may contain digits like 123, and you want to mark those rows as “Has Numeric Code”.

Table:

Add Column If Contains Number  Special Text in Power Query

Now follow the steps below:

In the Power Query editor, add a Custom Column. In the formula box, write a condition like:

if Text.Contains([Employee Code], "0")
 or Text.Contains([Employee Code], "1")
 or Text.Contains([Employee Code], "2")
 or Text.Contains([Employee Code], "3")
 or Text.Contains([Employee Code], "4")
 or Text.Contains([Employee Code], "5")
 or Text.Contains([Employee Code], "6")
 or Text.Contains([Employee Code], "7")
 or Text.Contains([Employee Code], "8")
 or Text.Contains([Employee Code], "9")
then "Has Numeric Code" 
else "No Numeric Code"
Add Column If Contains Number  in Power BI

You will now see the Numeric Flag column created using a custom column in the Power Query editor.

Add Column If Contains Number Special Text using Power Query

In M code, you can use:

= Table.AddColumn(Source, "Numeric Flag", each 
    if Text.Contains([Employee Code], "0")
     or Text.Contains([Employee Code], "1")
     or Text.Contains([Employee Code], "2")
     or Text.Contains([Employee Code], "3")
     or Text.Contains([Employee Code], "4")
     or Text.Contains([Employee Code], "5")
     or Text.Contains([Employee Code], "6")
     or Text.Contains([Employee Code], "7")
     or Text.Contains([Employee Code], "8")
     or Text.Contains([Employee Code], "9")
    then "Has Numeric Code" 
    else "No Numeric Code")

Add Column If Contains Text From Another Column using Power Query

Here we will check whether the text in one column appears inside another column.
For example: If the Department Name contains the Team Name, tag it as Match Found.

Table:

Add Column If Contains Text From Another Column using Power Query

Steps to Create a Custom Column:

  1. In Power Query editor, go to Add Column -> Custom Column.
  2. Enter the following details:
    • New column name: Dept-Team Match
    • Custom column formula:
if Text.Contains([Department Name], [Team Name]) 
then "Match Found" 
else "Not Matched"
Add Column If Contains Text From Another Column Power Query

You will now see the Dept-Team Match column created using a custom column in the Power Query editor.

Add Column If Contains Text From Another Column using Power Query in Power BI

M Code:

= Table.AddColumn(Source, "Dept-Team Match", each 
    if Text.Contains([Department Name], [Team Name]) 
    then "Match Found" 
    else "Not Matched")

Add Column If Column Contains Blank or Null in Power BI

You may want to label rows where a column is empty. For example, if the Customer Email is blank or null, mark it as “Missing Email”.

Table:

Add Column If Column Contains Blank or Null in Power BI

Follow the steps below to create a custom column:

  1. Open Power Query Editor -> Go to the Add Column tab. Click Custom Column.
  2. In the formula box, write a condition like:
if [Customer Email] = null or [Customer Email] = "" or [Customer Email] = "null"
then "Missing Email" 
else "Available"
Add Column If Column Contains Blank or Null power query in Power BI

Now, you will see the Dept-Team Match column created using a custom column in the Power Query editor.

Power BI add Column If Column Contains Blank or Null

M code:

= Table.AddColumn(Source, "Email Status", each 
    if [Customer Email] = null or [Customer Email] = "" or [Customer Email] = "null" 
    then "Missing Email" 
    else "Available")

In this tutorial, you learned different ways to add a column in Power Query when a value “contains” specific text. I started with a simple example using the Custom Column option and the Text.Contains a function. Then I showed how to do the same using M code in the Advanced Editor.

You also learned how to check for multiple keywords, how to detect numbers or special text inside a column, how to match text from another column, and how to identify blank or null values.

You may like the following Power BI tutorials:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Live Webinar

Quiz App Using SharePoint Framework (SPFx)

Learn to built a complete Quiz Management solution that enables admins to create and manage quizzes, categories, questions, and settings with an easy automated setup process in SharePoint. It also includes an interactive quiz experience for users and a powerful dashboard to track participation, analyze results, and view detailed performance reports with charts and answer insights.

📅 2nd June 2026 – 10:00 AM EST | 7:30 PM IST

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App