Forum Discussion

anvikuttu's avatar
anvikuttu
Advocate I
4 years ago
Solved

Need help on M Query

Hi Team, I need your help in solving in Power query. I have 2 tables Table A and Table B.  I am trying to update Table A (Result field)  by searching values from Table B in Table A. If the values a...
  • AlexisOlson's avatar
    4 years ago

    You aren't too far off but I think I'd write it like this:

    = Table.AddColumn(
        #"Changed Type1",
        "Custom",
        (t) => List.Last(
                   List.Select(
                       TableB[LookupValue],
                       each Text.Contains(t[Test], _)
                   )
               ) ?? "Not Found",
        type text
    )

     The "??" part indicates what to return if the preceding expression is null.

  • AlexisOlson's avatar
    AlexisOlson
    4 years ago

    Compute them separately and use if/then logic to return the text you want.

     

    (t) =>
        [
            Partial = List.Last(List.Select(TableB[LookupValue], each Text.Contains(t[Test], _))),
            Exact   = List.Last(List.Select(TableB[LookupValue], each t[Test] = _)),
            Text    =
                if Exact <> null then "Exact match " & Exact
                else if Partial <> null then "Partial match " & Partial
                else "No match"
        ][Text]