Forum Discussion
trying to extract file type from file path
- 5 years ago
Hi Anonymous - use this formula:
Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd})It will find the first period from the right (end) of the path, then give you all text after that period. Full M code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JclBCoAgEADAr4j33NondKtjHSPEYoWNckNF6PcZwdxmWbTzngPnB2Y+C0Vwe+ZClkOhlCUmuCkmCXC5G4YA2GILHX7+SLaXTU1GjUL226bDyhz19Lq+", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Path = _t]), #"Added Custom" = Table.AddColumn(Source, "Extension", each Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd})) in #"Added Custom"How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.
Hi Anonymous - use this formula:
Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd})
It will find the first period from the right (end) of the path, then give you all text after that period. Full M code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JclBCoAgEADAr4j33NondKtjHSPEYoWNckNF6PcZwdxmWbTzngPnB2Y+C0Vwe+ZClkOhlCUmuCkmCXC5G4YA2GILHX7+SLaXTU1GjUL226bDyhz19Lq+", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Path = _t]),
#"Added Custom" = Table.AddColumn(Source, "Extension", each Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd}))
in
#"Added Custom"
How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.
- Anonymous5 years agoNot applicable
will this still work if there's another period in the path? ie:
~/persons_Bob.Bobby R.Joe_2020-12-25.json
- edhans5 years ago
Community Champion
Yes. Did you try it? It will work if there are 1,000 periods in the path. It will always take the text after the last period.
- Anonymous5 years agoNot applicable
Confirmed, thanks! as an improvevment, are we able to apply this dynamically based on file type? ie: '~.tar.gz'