Forum Discussion
Error handling when table is empty
- Anonymous3 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
After trying all the different approaches suggested here I was still not able to solve the issue. Strangely it seems like try... otherwise would not catch this specific error. I have seen this being referenced to as a bug on other forums.
The solution ended up being retrieving two days of data from the API, instead of just today, ensuring that the returned table is never empty.
Thanks for all the help!
Thanks for that great suggestion of just getting more data to ensure no empty tables!