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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
PaulTHR
Frequent Visitor

Extract first integer and thPowerQuery a way to remove the quantity number and specific word

Hi - I need to create in PowerQuery a way to remove the quantity number and specific word "Piece" from a data set in Pbi PowerQuery.
I have managed to try a couple of methods including splitiing by delimiter but I lose the result completely when the word "Piece" is not in the record - looks like this:

Before                             After                   Unfortunately I am getting                      But what I want is                   
2 Piece TypeATypeATypeATypeA
2 Piece TypeBTypeBTypeBTypeB
2 Piece TypeCTypeCTypeCTypeC
TypeDTypeD TypeD
2 Piece TypeATypeATypeATypeA
3 Piece TypeBTypeBTypeBTypeB
3 Piece TypeCTypeCTypeCTypeC
4 Piece TypeDTypeDTypeDTypeD
TypeATypeA TypeA
4 Piece TypeBTypeBTypeBTypeB
4 Piece TypeCTypeCTypeCTypeC
4 Piece TypeDTypeDTypeDTypeD
TypeATypeA TypeA
5 Piece TypeBTypeBTypeBTypeB
5 Piece TypeCTypeCTypeCTypeC
TypeDTypeD TypeD
5 Piece TypeATypeATypeATypeA
5 Piece TypeBTypeBTypeBTypeB

I had thought about find/replace but the numbers can be anything so dont want a script for every number option.

1 ACCEPTED SOLUTION
Dinesh_Suranga
Continued Contributor
Continued Contributor

@PaulTHR 

First add a new column with following code.

Text.Remove( [ColumnName], {"0".."9"} )

Then replace " Piece ".

add space before and after Piece if there are space in existing column.

Thank you.

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

I think you can also do this purely with the GUI by using Text After Delimiter using a space and scanning from the right rather than the left.

AlexisOlson_0-1665589010130.png

 

This produces code like

Table.AddColumn(
    #"Changed Type",
    "Text After Delimiter",
    each Text.AfterDelimiter([Before], " ", {0, RelativePosition.FromEnd}),
    type text
)
Dinesh_Suranga
Continued Contributor
Continued Contributor

@PaulTHR 

First add a new column with following code.

Text.Remove( [ColumnName], {"0".."9"} )

Then replace " Piece ".

add space before and after Piece if there are space in existing column.

Thank you.

Thanks very much that did the trick.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.