Forum Discussion
Anonymous
5 years agoNot applicable
trying to extract file type from file path
given the path of affinity/Silver/active_investors/person/map/In/2020/12/12/persons_Bob R. Joe_2020-12-12.json Extracting after the after the delmiter using "." will work on file paths th...
- 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.
Anonymous
5 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
edhans
Community Champion
5 years agoYes. 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.