Forum Discussion
Power Query - Prevent complete dataset to be refreshed when there's something wrong with the source
Sure. You would need to do a row count on the source table. Then if it has 0 records, return an error. That will halt the query refresh.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAeJYnWglIyDLGMwyBrJMlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}}),
IsValidData =
if Table.RowCount(#"Changed Type") = 3
then
error [
Reason = "SourceTableEmpty",
Message = "Source table has no records",
Detail = "Database.TableName"
]
else #"Changed Type"
in
IsValidData
In this example, I tested for 3 records so it would error out. But use 0 in your actual use case. It will return that error to the service.
How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.
Thanks for the reply. As soon as possible I'll test it.
- edhans4 years agoCommunity Champion
I know it works, because after I came up with it, I implemented it on a dataset I was having a similar issue with, and your question sparked the answer I needed. 😂
Let me know if you have any questions!