Forum Discussion

CRBailey's avatar
CRBailey
Regular Visitor
4 years ago
Solved

Using Text Comparison to Create Reference Column Based on Values of Another Tables Column

This is my first crack at requesting assistance, so I will do my best:    I have two tables one with a couple million rows, the column in question has roughly 500 unique values (Table 1, Column A )...
  • AlexisOlson's avatar
    AlexisOlson
    4 years ago

    A loop might be overkill. If the columns involved are text data type, then you can filter Column B using Text.StartsWith within the filter condition like this:

     

     

    Using your original columns:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrQ0MDG3UIrViVYyMjA1MLFEZwIVGEMVgJgWhhCmobmxiRlMrTFMm6GxkQWUaWRkAGLGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column A", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "New Column", (r) =>
            List.First(
                List.Select(
                    #"Table 2"[Column B],
                    each Text.StartsWith(r[Column A], _)
                ), ""
            ), type text)
    in
        #"Added Custom"