Extract Text in Power BI Power Query Using Add Column [With Various Examples]

While working on a client report, there was a requirement to clean and format text data before using it in visuals. The source file contained values such as codes, names, and descriptions combined into a single column. The client wanted only specific parts of the text, such as the first few characters, the last value, or the text before and after a symbol.

To solve this requirement, I used the Extract option in Power Query. This feature helps extract only the required part of the text and create a new column without changing the original data.

In this tutorial, I will explain how to use the Extract in the Power Query Add Column. I will cover:

  • Extract Text Length in Power BI Power Query
  • Get First Characters from Text in Power BI Power Query
  • Extract Last Characters from a Text Column in Power BI
  • Extract a Specific Text Range in Power BI Power Query
  • Extract Text Before a Delimiter in Power BI Power Query
  • Extract Text After a Delimiter in Power BI Power Query
  • Extract Text Between Two Delimiters in Power BI Power Query

Extract Text in Power BI Power Query Using Add Column

In this example, I am using the Super Store sample data shown below. You can also download the sample data from the link provided and use it in your own report.

Extract Text in Power BI Power Query Using Add Column

Extract Text Length in Power BI Power Query

For this example, I will extract the text length from the Product Name column using Power BI Power Query. The goal is to find how many characters are present in each product name and store the result in a new column.

To do this, follow the steps below:

  1. Open Power BI Desktop. Load the Excel file (Super Store data) using the Get Data option.
text range power query in Power BI
  1. Go to the Home tab and click Transform data to open Power Query Editor.
How do I extract a specific text with a specific text length in Power BI
  1. Select the text column for which you want to find the length (for example, Product Name). Go to the Add Column tab. Click Extract -> select Length.
How to extract exact string lengths from a column in Power Query
  1. Power Query will create a new column that shows the number of characters in each text value. Rename the new column if required.
Extract Length Using Power Query or Get & Transform in Power BI

This is how you can extract text length using Add Column -> Extract -> Length in Power BI Power Query.

Get First Characters From Text in Power BI Power Query

For this example, I will extract the first 3 characters from the Order ID column using Power BI Power Query, since those characters represent the product category.

Extract First, Middle and Last Characters in a Text with Power BI

To do this, follow the steps below:

  1. Open Power BI Desktop. Load the Excel data using the Get Data option.
  2. Go to the Home tab and click Transform data to open Power Query Editor.
Extract first 3 character in Power Bi
  1. Select the Order ID column. Go to the Add Column tab. Click Extract and select First Characters.
Extract first 3 characters in Power Query
  1. In the dialog box, enter three as the number of characters. Click OK.
Return x numbers after the first character in power BI

Then you can see a new column will be created showing the first 3 characters from the Order ID.

Get First Characters from Text in Power BI Power Query

This is how you can extract the first three characters from the Order ID column in Power BI Power Query.

Extract Last Characters From a Text Column in Power BI

In this example, I will extract the last four characters from the Order ID column using Power BI Power Query. The last characters of the Order ID represent the order number, which helps track and sort orders.

Follow the steps below:

  1. Open Power BI Desktop and load the Excel data using the Get Data option. Go to the Home tab and click Transform data to open Power Query Editor. Then you can see the data in the Data Pane.
Get last string element from a column into a new column in Power BI
  1. Select the column you want to extract, in my case, Order ID. Go to the Add Column tab, click Extract, and then select Last Characters.
Extract all characters EXCEPT the last X amount in power BI
  1. In the dialog box, enter four as the number of characters and click OK.
How to extract characters from a string in Power BI

Power Query will create a new column that shows the last four characters from each Order ID value.

Extract Last Characters From a Text Column in Power BI

This is how you can extract the last characters from a text column using Add Column -> Extract -> Last Characters in Power BI Power Query.

Extract a Specific Text Range in Power BI Power Query

While working on a client report, the Order ID column followed a fixed format. The year of the order was always stored in the middle of the Order ID (characters 4 to 7).

How to Extract Substring in Power BI (With Examples)

I wanted the order year in a separate column for filtering and reporting.

To do this, follow the steps below:

  1. Open Power BI Desktop and load your data. Go to Home, click Transform data to open Power Query Editor.
  2. Select the Order ID column. Go to the Add Column tab. Click Extract, select Range.
DAX find last occurrence of character in string
  1. In the dialog box:
    • Start index: 3
    • Number of characters: 4
  2. Click OK.
How to Extract Text from Long Text or String

Then you can see a new column will be created showing the order year.

Extract a Specific Text Range in Power BI Power Query

This is how you can extract a specific text range from a column using Power BI Power Query.

Extract Text Before a Delimiter in Power BI Power Query

In this example, I have a dataset where the Customer Email column contains values in this format: username@domain.com.

Extract Text Before Delimiter (Power Query) in Power BI

Here, I want to extract only the text before the @ symbol, because it represents the user name. To do this, I will use the Extract Text Before Delimiter option in Power BI Power Query.

Follow the steps below to Extract Text Before a Delimiter:

  1. In Power BI Desktop, open Power Query Editor. Select the Customer Email column.
  2. Go to the Add Column tab. Click Extract, select Text Before Delimiter.
How to Extract Text with Delimiters in Power BI
  1. In the dialog box, enter @ as the delimiter. Click OK.
Extract Text in Power Query

A new column will be created showing the text before the @ symbol.

Extract Text Before a Delimiter in Power BI Power Query

You need to replace the dot with a blank space to find the Customer’s name. This is how you can extract text before a delimiter using Power BI Power Query.

Extract Text After a Delimiter in Power BI Power Query

In this example, I am using the same data set, but I want to extract only the text after the @ symbol, since it represents the email domain (e.g., gmail.com or outlook.com).

Let’s see how to do:

  1. Open the Power Query editor and select the column you want to extract, in my case, the Customer Email column.
  2. Go to the Add Column tab. Click Extract, select Text After Delimiter.
Extract Text Before Delimiter for multiple columns in a single query step
  1. In the dialog box, enter @ as the delimiter. Click OK.
extract text after delimiter using a delimiter column in Power BI

You can see that a new column will be created showing the text after the @ symbol.

Extract Text After a Delimiter in Power BI Power Query

Extract Text Between Two Delimiters in Power BI Power Query

While working on a sales report, the required information was stored between two symbols inside a text value. The Order Reference column contained values where important details were placed inside square brackets.

How to Extract the Text between the delimiters in Power BI

In this example, I want to extract only the text between [ and ], such as Furniture, Technology, and Office Supplies.

To do this, follow the steps below:

  1. Open Power BI Desktop and load the data using the Get Data option.
  2. Go to the Home tab and click Transform data to open Power Query Editor.
Extract text between two delimiters in power bi power query without
  1. Select the Order Reference column from the table. Go to the Add Column tab in the Power Query Editor. Click Extract, and then select Text Between Delimiters.
extract every occurrence of the text between two delimeters in Power BI
  1. In the dialog box:
    • Enter [ as the starting delimiter.
    • Enter ] as the ending delimiter.
  2. Click OK.
Add column to extract text after multiple possible delimiters

Power Query will create a new column that shows only the text between the square brackets. Rename the new column if required.

Extract Text Between Two Delimiters in Power BI Power Query

In this tutorial, I explained how to use the Extract option in Power Query Add Column to work with text data. I showed how to extract the text length, the first and last characters, and a specific text range from a column. I also covered how to extract text before a delimiter, text after a delimiter, and text between two delimiters.

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.

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