Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

If table is empty, insert null value, else carry on.

Hello community,   I am struggling with a bit of M code.   I am trying to search for a value which in some cases is not found, resulting in an empty table. For reference, the table has only 1 col...
  • Anonymous's avatar
    Anonymous
    5 years ago

    I figured it out.... the table name is the name of the previous step. I was calling it by a different name. It's always a small problem isn't it.... anyway thanks for your help!

     

    The end of the code now reads:

     

    #"Removed Other Columns3" = Table.SelectColumns(#"Renamed Columns2",{"BatchNo"}),
        #"Changed Type3" = Table.TransformColumnTypes(#"Removed Other Columns3",{{"BatchNo", type text}}),
        #"AddNull" = if Table.IsEmpty(#"Changed Type3") then Table.InsertRows(#"Changed Type3",0, { [BatchNo = "null"] }) else #"Changed Type3",
        #"Search Batch Number" = #"AddNull"{0}[BatchNo]
    in
        #"Search Batch Number"

     

    All I had to do was change Table.InsertRows(BatchNumber2, 0, { [BatchNo = "null"] }) to Table.InsertRows(#"Changed Type3", 0, { [BatchNo = "null"] }).