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
Whatever step causes that error, and it's difficult to tell without seeing your steps, wrap like this:
= if Table.IsEmpty(HereIsYourCurrentExpressionThatGivesErrorsWhenEmpty) then Table.FromRecords({[Column1 = "SomeText", Column2 = "SomeOtherText", Column3 = "MoreText"]}, {"Column1", "Column2", "Column3"}) else HereIsYourCurrentExpressionThatGivesErrorsWhenEmpty
Basically, If this expression returns an empty table than make a table like so.
---Nate