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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Shelley
Post Prodigy
Post Prodigy

Conditionally Remove Substring from Beginning of Column

Hi Team, 

Another plea for help here. I'm trying to clean up some messy Job Title data. Sometimes there is a job code at the beginning of the Job title that is delineated by " - "; however, this same substring can appear in some of the actual Job Titles, so IF the substring " - " is there, I want to remove everything before only the first instance

 

Here's some data just for example:

Job Title

Material Handler Level 1P
Material Handler Level 2P
Material Handler Level 3P
Material Handler Level 4P
OM.015.S3 - Equip Maintenance Technician Level 3P
OM.015.S4 - Equip Maintenance Technician Level 4P
OM.015.S5 - Equip Maintenance Technician Level 5P

 

I've tried this, but am getting an error.

#"Trimmed Text1" = Table.TransformColumns(#"Trimmed Text", {{"Job Title", each if Text.Contains([Job Title], " - ") then Text.AfterDelimiter(_, " - ") else [Job Title] , type text}})


Here's the error I receive:

Expression.Error: We cannot apply field access to the type Text.

 

When I tried it without the condition, it erased the field, which I'm thinking happened because those first fields in the data did not contain the " - " string.

Thanks in advance for the help.

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Shelley 

 

Change [Job Title] to _

#"Trimmed Text1" = Table.TransformColumns(#"Trimmed Text", {{"Job Title", each if Text.Contains(_, " - ") then Text.AfterDelimiter(_, " - ") else _ , type text}})

For the 2nd argument of Table.TransformColumns, the second item within each inner list needs to be a function taking a single argument, which is represented by _ when using the each syntax.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

5 REPLIES 5
v-junyant-msft
Community Support
Community Support

Hi @Shelley ,

Please try this:

#"Trimmed Text1" = Table.TransformColumns(#"Changed Type", {{"Job Title", each if Text.Contains(_, " - ") then Text.AfterDelimiter(_, " - ", {0, RelativePosition.FromStart}) else _ , type text}})

And the final output is as below:

vjunyantmsft_0-1708668904338.png


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

Hi,

 

Under Transform Tab there is option Extract Text after delimiter. Try that it works.

poojashribanger_0-1708664986638.png

 

Regards,

Poojashri

@poojashribanger Great idea, thanks. However, this gave me blanks just like when I tried to do it manually.

OwenAuger
Super User
Super User

Hi @Shelley 

 

Change [Job Title] to _

#"Trimmed Text1" = Table.TransformColumns(#"Trimmed Text", {{"Job Title", each if Text.Contains(_, " - ") then Text.AfterDelimiter(_, " - ") else _ , type text}})

For the 2nd argument of Table.TransformColumns, the second item within each inner list needs to be a function taking a single argument, which is represented by _ when using the each syntax.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Thanks @v-junyant-msft and @OwenAuger - and Owen for explaining it. Unfortunately, I still don't understand single argument and inner list terminology, but I love having the explanation. One of these days I'll understand M better. In the meantime, this worked! THANK YOU both.

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.