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 community!I have a column that contains a string in this format:
Type1 Type2 Product "in"Country City
| String |
| Glas Tube A inFrance Lyon |
| Glas Tube B inSpain |
| Glas Tube C |
| Wood Chair A1 Spain Madrid |
Now, based on the first word in the column I would like to apply an individual split of this column:
How would you apply this kind of logic within power query?
Solved! Go to Solution.
Hi @joshua1990
You could give this a go.
let
ColNames = {"Type1", "Type2", "Product", "Country", "City"},
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs9JLFYIKU1KVXBUyMxzK0rMS05V8KnMz1OK1UGWdQLKBhckZqKLO4P54fn5KQrOGYmZRQqOhgpgdQq+iSlFmSlKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [String = _t]),
SplitCol = Table.SplitColumn(Source, "String", Splitter.SplitTextByWhitespace() ),
TrimStart = Table.TransformColumns(
Table.RenameColumns( SplitCol, List.Zip( { Table.ColumnNames( SplitCol ), ColNames })),
{{"Country", each Text.TrimStart(_, {"i", "n"}), type text }}
)
in
TrimStart
With this result
Hello
Here is the magic code
= Table.AddColumn(#"Renamed Columns1", "New", each Text.Select([Name], {"a".."z"}))
We can subsitute Upper and Lower case or number {0..9}.
Thanks
John Haase
Hi @joshua1990
You could give this a go.
let
ColNames = {"Type1", "Type2", "Product", "Country", "City"},
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs9JLFYIKU1KVXBUyMxzK0rMS05V8KnMz1OK1UGWdQLKBhckZqKLO4P54fn5KQrOGYmZRQqOhgpgdQq+iSlFmSlKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [String = _t]),
SplitCol = Table.SplitColumn(Source, "String", Splitter.SplitTextByWhitespace() ),
TrimStart = Table.TransformColumns(
Table.RenameColumns( SplitCol, List.Zip( { Table.ColumnNames( SplitCol ), ColNames })),
{{"Country", each Text.TrimStart(_, {"i", "n"}), type text }}
)
in
TrimStart
With this result
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 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 7 | |
| 5 | |
| 5 |