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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Removing all text except certain characters

Hello, I'm new to using PowerQuery and I'm trying to clean up a column on one table to create a relationship with another table.

 

The column I'm attempting to clean up is a free text field from a maintenance system, and the goal is to remove all unrequired text and leave only what we want EX: MA-1405. 

 

I've played around with the Replace Values tool, trying to remove and change as much as I can to then extract text before delimiter, however with it being a free text field there are plenty of delimiters and occassionally there is text before the MA# 

 

I know that in Excel you can use ** to represent a string of characters and was wondering if a similar feature existed here as well?

 

Ideally I'd like to put in one formula to replace all values except "MA-***"

3 REPLIES 3
edhans
Super User
Super User

You can add a column with this formula, then remove the original column, and presumably filter out the rows that return null.

 

if Text.Contains([Column1],"MA-") = true 
then Text.Middle([Column1],Text.PositionOf([Column1],"MA-"),7)
else null

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

have you been able to solve the problem with the replies given?

If so, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

All the best

Jimmy

Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

you can use a combination of Text.PositionOf and Text.Middle. Adding a try otherwise enablse to identifying those rows that don't contain any MA-****

 

let
	Source = #table
	(
		{"FreeTextColumn"},
		{
			{"xxasdfMA-1450…sdf"},	{"sssktest MA-1111"},	{"kkMA-11558888884"},	{"88oeoeMA-15444"}
		}
	),

	AddColumn = Table.AddColumn
	(
		Source,
		"extract MA",
		(add)=> try
		Text.Middle
		(
			add[FreeTextColumn],
			Text.PositionOf(add[FreeTextColumn], "MA-"),
			7
		)
		otherwise 
		"contains NO MA-"
	)
in
	AddColumn

 

 

Copy paste this code to the advanced editor to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

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