Forum Discussion
Excel power query with empty table
encapsulate your
Table.TransformColumnTypes
line with a try...otherwise... construct, or check the returned size of Data2, and then only do the rest of the processing if it is non-zero.
In the grand scheme of things you need to worry much more about why that table is sometimes empty. Unstable web server? timing issue?
it's returning a calendar table of stocks due for earning release. The table is empty when there are no stocks due that day.
If I understand what you are saying, I should add something that will check if the table is empty, then stop if it is, then otherwise proceed with the rest. The problem is, I have no experience coding. If it's just a line, would you mind helping me here ? Would save me lots of time trying to figure it out, and would be well appreciated. Or at least point me out to which instruction I would need to look for.
Thanks so much for your reply.
- mahoneypat6 years agoMicrosoft Employee
You can just wrap your last step in the query with try ... otherwise null.
let
Source = ...
#"Change Type" = try ... otherwise null
in
#"Change Type"
Note that may cause errors downstream if that query is used in other queries, or if you have DAX calculated column(s). If that is the case, you can make a query that has some mock data that matches the format of your real data. In your Source step, you can use a Source = try Web.Contents(...) otherwise mockdataquery
That way all the downstream stuff will still work.
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
- serhito6 years agoRegular Visitor
I appreciate your help.
As I mentionned, I have no coding experience, so I wouldn't know where to place what you suggested.
I decided to go with googlesheet. It gives more flexibility, and no error for the task that I want to do.