Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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 TypeA | TypeA | TypeA | TypeA |
| 2 Piece TypeB | TypeB | TypeB | TypeB |
| 2 Piece TypeC | TypeC | TypeC | TypeC |
| TypeD | TypeD | TypeD | |
| 2 Piece TypeA | TypeA | TypeA | TypeA |
| 3 Piece TypeB | TypeB | TypeB | TypeB |
| 3 Piece TypeC | TypeC | TypeC | TypeC |
| 4 Piece TypeD | TypeD | TypeD | TypeD |
| TypeA | TypeA | TypeA | |
| 4 Piece TypeB | TypeB | TypeB | TypeB |
| 4 Piece TypeC | TypeC | TypeC | TypeC |
| 4 Piece TypeD | TypeD | TypeD | TypeD |
| TypeA | TypeA | TypeA | |
| 5 Piece TypeB | TypeB | TypeB | TypeB |
| 5 Piece TypeC | TypeC | TypeC | TypeC |
| TypeD | TypeD | TypeD | |
| 5 Piece TypeA | TypeA | TypeA | TypeA |
| 5 Piece TypeB | TypeB | TypeB | TypeB |
I had thought about find/replace but the numbers can be anything so dont want a script for every number option.
Solved! Go to Solution.
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.
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.
This produces code like
Table.AddColumn(
#"Changed Type",
"Text After Delimiter",
each Text.AfterDelimiter([Before], " ", {0, RelativePosition.FromEnd}),
type text
)
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 6 | |
| 5 |