Forum Discussion

magnus_b's avatar
magnus_b
Advocate II
5 years ago
Solved

Error handling when table is empty

Hi!   I am using direct query against an API, that will return a table with a row for each visitor today. At the beginning of the day, there are no rows in this table, so the query will produce an ...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Try this:

     

    = Table.AddColumn(PriorStepOrTableName, "TableToExpand", each if Table.IsEmpty(_[Data]) then Table.FromColumns({{null}, {null}, {null}, {null}}, {"Column1", "Column2", "Column3", "Column4"}) else [Data])

     

    Now if the table is empty, you'll get a 4 column, 1 row table of null values.  Make as many nulls and column names as you need.  You should replace my "Column1" names with the actual column names.

     

    --Nate