Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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...
  • edhans's avatar
    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.