Forum Discussion
Build Table/Query Reference Using Other Query Steps as "Variables"
- 2 years ago
Hi
Maybe with Expression.Evaluate
let
Variable1 = "QueryB Part1"
Variable2 = "QueryB Part2"
QueryReference = Expression.Evaluate("#""" & Variable1 & " - " & Variable2 & """", #shared)
in
QueryReferenceStéphane
- 2 years ago
FOLLOW UP - LIMITED USE SOLUTION:
While this solution works in Power Query Editor, it does not work when loading changes into the actual Model (i.e. after pressing "Close & Apply"). For some reason, a blank table is returned.
I narrowed down the issue to using the "#shared" method of referencing a query. Apparently it doesn't work outside the preview/Editor environment. To test this idea, I actually performed the same steps as the = Expression.Evaluate( ..., #shared ) solution provided by slorin (which, again, works in preview/Editor), except manually.
- Created a step Source = #shared. This pulls up the list of queries and library of functions as expected.
- Clicked on "Table" next to the table I wanted to open.
As expected, in preview/Editor, the table came up as expected. But again, like with the Evaluate.Expression() function, when this query loaded into my Model, it returned a blank table.
Unfortunately, this means what I was trying to accomplish originally is still unsolved.
Hi mm5308 ,
I'm sorry I may not have a good understanding of what you're hoping to accomplish.
Your direct return from this code
let
Name1 = "Name1"
Name2 = "Name2"
QueryReference = "#""" & Name1 & " - " & Name2 & """"
in
QueryReference
is shown below:
It simply returns a string without any function.
But in this piece of code:
let
Source = #"Name1 - Name2"
in
Source
The #"Name1 - Name2" is a predefined step that contains the function, so instead of just returning a string, it will return the result of the data table you get after all the steps in this function are completed.
If I'm not understanding you correctly, could you please provide me with the sample data if you can and the final results you're hoping to get, that would be helpful, thanks!
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- mm53082 years ago
Helper I
Hi Anonymous,
Thank you for replying. One thing you said made me realize that the way I worded the issue is a little misleading, or perhaps didn't explain it well. I will edit it after this post.
I know that I can directly reference another query to produce a table by directly typing the name of the query as you suggested. That's exactly what I'm trying to avoid though. What I really want is a way to build a query name through "variable" references. That way I can copy and paste the query and change the variables to reference the different tables I want for each new query.
Does that clarify, and do you have any additional insights?