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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
Community Champion
Community Champion

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.