Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Table.SelectRows in conjunction with if statement from another table

Hi,    Trying to utilise an if statement within a Table.SelectRows and not having any joy, had a good look around and can't quite find the right thing....   So table Inventory(90+) lists all inve...
  • jennratten's avatar
    4 years ago

    Assuming that your REP and CSR are values and not tables, and you want to use one conditional statement, you would do it like this...

     

    = Table.SelectRows(#"Sorted Rows", each if CSR = null
    then [REP] = REP else [CSR] = CSR )

     

    Example:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUpRitWJVkoCslLhrDQwKxnISgezUuCsVCArQyk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CSR = _t, REP = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"CSR", type text}, {"REP", type text}}),
        CSR = null, //"b",
        REP = "h",
        SelectRows = Table.SelectRows(#"Changed Type" , each if CSR = null then [REP] = REP else [CSR] = CSR )
    in
        SelectRows