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
glmoon5
Helper I
Helper I

Remove portion of Text from 1 table column that is already another complete column text

I have 2 columns in a 'Combined Data' table:

 

Category

Class

 

The 2 columns look like this:

 

 

CategoryClass
BREAKFAST BREADBREAKFAST BREAD ENGLISH MUFFIN
BREAKFAST BREADBREAKFAST BREAD LOAF BREAD
BREAKFAST BREADBREAKFAST BREAD SPECIALTY BAGEL
BREAKFAST BREADBREAKFAST BREAD TRADITIONAL BAGEL
BUNS & ROLLSBUNS & ROLLS BFY
BUNS & ROLLSBUNS & ROLLS BREADSTICKS -NS
BUNS & ROLLSBUNS & ROLLS SPECAILTY
BUNS & ROLLSBUNS & ROLLS TRADITIONAL
LOAF BREADLOAF BREAD FRENCH -NS
LOAF BREADLOAF BREAD SANDWICH
LOAF BREADLOAF BREAD SOURDOUGH -NS
LOAF BREADLOAF BREAD VALUE ADDED
LOAF BREADLOAF BREAD VARIETY

 

As you can see the class column has the category name at the beginning of the "actual" Class Name I want to display and I am looking for a way to have the query remove it from the Class column.

1 ACCEPTED SOLUTION
kushanNa
Super User
Super User

Hi @glmoon5 

 

you can do this in Power query side or in DAX side 

 

please use the following prefered method you like 

 

If you're in Power Query (Transform Data):
You can create a new column like this:

Go to Transform Data.

Add a Custom Column with the following formula:

Text.Trim(Text.Replace([Class], [Category], ""))

kushanNa_0-1744742898832.png


This replaces the category name in the class and then trims any leading/trailing spaces.

 

If you're in DAX (Calculated Column):
Use this DAX formula to create a new column:

CleanClass =
TRIM(
SUBSTITUTE('Combined Data'[Class], 'Combined Data'[Category], "")
)

kushanNa_1-1744742936366.png

 

This will also remove the category from the beginning and clean up spaces.

 

 

View solution in original post

3 REPLIES 3
kushanNa
Super User
Super User

Hi @glmoon5 

 

you can do this in Power query side or in DAX side 

 

please use the following prefered method you like 

 

If you're in Power Query (Transform Data):
You can create a new column like this:

Go to Transform Data.

Add a Custom Column with the following formula:

Text.Trim(Text.Replace([Class], [Category], ""))

kushanNa_0-1744742898832.png


This replaces the category name in the class and then trims any leading/trailing spaces.

 

If you're in DAX (Calculated Column):
Use this DAX formula to create a new column:

CleanClass =
TRIM(
SUBSTITUTE('Combined Data'[Class], 'Combined Data'[Category], "")
)

kushanNa_1-1744742936366.png

 

This will also remove the category from the beginning and clean up spaces.

 

 

Exactly, as always the same approach and the same concept for DAX, SQL and M languages but with slightly different syntax

rosha_rosha
Resolver II
Resolver II

1. It is in Sql Server

SELECT
Category,
TRIM(REPLACE(Class, Category, '')) AS  Class FROM
[Combined Data];

UPDATE [Combined Data]
SET Class = TRIM(REPLACE(Class, Category, ''));

2. It is in Dax

Cleaned Class =
TRIM(
SUBSTITUTE(
'Combined Data'[Class],
'Combined Data'[Category],
""
)
)

If it works out for you, accept it as SOLUTION so other users can also benefit from it!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors