Forum Discussion

MatM's avatar
MatM
Microsoft Employee
4 years ago
Solved

Filtering based on prefix match

I have two tables.   Table1 -- main data Path Interesting data Interesting data /uk/london/central/bank ...   /uk/london/central/mayfair     /uk/london/central/mayfair     /...
  • KNP's avatar
    4 years ago

    Hi MatM,

     

    You could use the 'fuzzy merge' option to match on Path. You may need a little trial and error to get the settings just right, but in your sample data, it worked with the defaults.

     

    let
      Source = Table.FromRows(
        Json.Document(
          Binary.Decompress(
            Binary.FromText(
              "i45W0i/N1s/Jz0vJz9NPTs0rKUrM0U9KzMtW0lHS09MDkgpKsTpYVeUmVqYlZhaBlZCvrDy1uARDLjkxN6koMyU9FSETCwA=",
              BinaryEncoding.Base64
            ),
            Compression.Deflate
          )
        ),
        let
          _t = ((type nullable text) meta [Serialized.Text = true])
        in
          type table [Path = _t, #"Interesting data" = _t, #"Interesting data.1" = _t]
      ),
      #"Changed Type" = Table.TransformColumnTypes(
        Source,
        {{"Path", type text}, {"Interesting data", type text}, {"Interesting data.1", type text}}
      ),
      #"Merged Queries" = Table.FuzzyNestedJoin(
        #"Changed Type",
        {"Path"},
        TableB,
        {"Path"},
        "TableB",
        JoinKind.LeftOuter,
        [IgnoreCase = true, IgnoreSpace = true]
      ),
      #"Expanded TableB" = Table.ExpandTableColumn(#"Merged Queries", "TableB", {"Scope"}, {"Scope"})
    in
      #"Expanded TableB"

     

    PBIX example attached for reference.

    Hope this helps.