Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Storing value in variable, so it can be referenced without reevaluation




URL = "MyRestApiGetQuery",

Source = if try Web.Contents(URL)[HasError]=true and Web.Contents(URL)[Error]="text that equates to true",

                    then "error identified",

                    else  "something else"




1: Will the above code send two identical requests to the server? I'm assuming yes


2:Is it possible to somehow reuse the return of the first request in the 'and' statement, so that I dont have to query the server twice? 




Edit: Perhaps and hopefully better questions.


    3: Is it possible to store the result of an expression in a variable in memory?  

    4: If yes, and this is what Table/List.Buffer does, how is that particular result referenced?


var = Table.Buffer(Mytable)

var2 =  var


var2 will just force evaluation of Table.Buffer(Mytable) again? Does something akin to below exist?


var = Table.Buffer(Mytable)

var2 =  FromMemory(var)


I read that this is possible in DAX, if i understood that correctly,


"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."


Thanks again!

Community Champion
Community Champion

Hello @Antesamegutt 


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

Have fun





I abused a random joke generating API 


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


URL = "",
Jokesetup = Json.Document(Web.Contents(URL))[setup],
Jokeoutput =

// to 100 -- jokesetup is always the same

in Jokeoutput





URL = "",


Jokeoutput =

// - 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

in Jokeoutput


Helpful resources

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors