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
Hi magnus_b
Can you provide the table that you get in the first step, Source? The M code provided does not work on my side (I guess I need to install the connector or similar)
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- magnus_b5 years agoAdvocate II
Hi AlB !
Here is the table returned in the first step:
The second step returns this table:
And the problem occurs if the "Table" in column Data in step 2 is empty. You can see the error I get here, when I try to view the table in column data in step 2:
Thank you for your help, really appreciate it!