Forum Discussion

Magnus-CPH-DK's avatar
Magnus-CPH-DK
Helper II
3 years ago
Solved

VLookup in the same table

Hi guys,   I can't seem to figure out how to do a VLookup as one would do it in Excel for this particular problem. I want to do the following:   "For each [Forudgående Kontrolnummer] that exists...
  • v-yanjiang-msft's avatar
    3 years ago

    Hi Magnus-CPH-DK ,

    According to your description, here's my solution.

    Add a custom column.

    if Table.RowCount(Table.SelectRows(#"Changed Type",(x)=>x[Kontrolnummer]=[Forudgående Kontrolnummer]))=0 then null else Table.SelectRows(#"Changed Type",(x)=>x[Kontrolnummer]=[Forudgående Kontrolnummer]){0}[Kontrolnummer_Type]

    Get the correct result.

    Here's the whole M syntax:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlbSUTJ2BBJKsTrRSqZAhimcZwZkmMF55kCGOYhnAuZaAFkWLiAxMNcSyLJEcA0NgExDA6hALAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Kontrolnummer = _t, Kontrolnummer_Type = _t, #"Forudgående Kontrolnummer" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Kontrolnummer", Int64.Type}, {"Kontrolnummer_Type", type text}, {"Forudgående Kontrolnummer", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Table.RowCount(Table.SelectRows(#"Changed Type",(x)=>x[Kontrolnummer]=[Forudgående Kontrolnummer]))=0 then null else Table.SelectRows(#"Changed Type",(x)=>x[Kontrolnummer]=[Forudgående Kontrolnummer]){0}[Kontrolnummer_Type])
    in
        #"Added Custom"

    I attach my sample below for your reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.