"By using a variable, you can get the same outcome, but in a more readable way. In addition, the result of the expression is stored in the variable upon declaration. It doesn't have to be recalculated each time it is used, as it would without using a variable. This can improve the measure's performance."
you can do like this and store the complete result in a variable, but probably is quering the website twice also here, because of lazy evaluation of M
URL = "MyRestApiGetQuery",
QueryWEB= try Web.Contents(URL)
if QueryWEB[HasError]=true then
if QueryWEB[Error]="text that equates to true" then
then "error identified",
else "something else"
else null //When nor error was identified
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you) Kudoes are nice too
If the calls were done through a variable, like in your code, then the contents of the variable would never change and so I think the query was run only once
If the calls were done 'naked', then they would often but not always have the same contents, leading me to believe the query was ran multiple times. The results of second below query are kind of mysterious
// - to 100, result of Web.Contents vary, but hard to figure out what is going on. The server should return a 4xx error if 100 requests are received from same ISP in 15 minutes, but above code will work even with 150 Web.Contents. It seems some under the hood power query features kick in after 10 or so W.C() and the same result is returned for the remainder of W.C()'s