Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ronrsnfld
Super User
Super User

Query string reference problem

Based on other topics, I can refer to queries using strings. And the query works as desired in the Power Query UI.

However, when I try to "Close and Apply", I receive an error message

 

ronrsnfld_0-1705488052651.png

 

If I run the same query in Microsoft Excel, there is no error on "Close and Load". The error only occurs in Power BI.

 

The use case is that I have a situation where there are multiple queries, but I only want to pick out those queries that end with a four digits representing a year in the range of this decade.

 

I do have other methods that I can use, but why doesn't this work? And why is the problem only with PBI and not with Excel?

 

Simplified code to show the problem, with hard-coded text strings rather than the more complex List.Select method that is unneccessary to demonstrate.

 

Assume the PQ has multiple queries

 

ronrsnfld_1-1705488577451.png

 

The following code runs to completion in PQ but causes the error message with Close and Apply

 

 

 

 

 

let
    queries=#sections[Section1],
    
    #"Selected Fields" = {"Table2022","Table2023","Table2024"},
    

    queryList = Record.FieldValues(Record.SelectFields(queries,#"Selected Fields")),
    combine = Table.Combine(queryList)
in
    combine

 

 

 

 

 

 If the queryList is replaced with the actual query names, eg:

 

 

 

 

 

queryList = {Table2022,Table2023,Table2024},

 

 

 

 

 

then the query runs and Close and Apply works without an error.

2 ACCEPTED SOLUTIONS
BA_Pete
Super User
Super User

Hi @ronrsnfld ,

 

As far as I'm aware, the intrinsic variables (#sections, #shared) can only be used within PQ when using PBI Desktop and not passed to the model. My assumption is, because they are environmental keywords i.e. they give information about the current environment, and the data model can't give that environmental info, this is what breaks it.

Why it seems to work in PQ for Excel I have no idea.

 

You could possibly try @'ing Ehren into this thread if you need the technicals on it.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

Ehren
Microsoft Employee
Microsoft Employee

For perf reasons, in PBIDesktop refresh, we trim any queries that aren't being referenced (directly or indirectly) from the mashup document and replace them with a null value. References by name via #sections or #shared don't count, so they get turned into null.

View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

Hi @ronrsnfld ,

 

As far as I'm aware, the intrinsic variables (#sections, #shared) can only be used within PQ when using PBI Desktop and not passed to the model. My assumption is, because they are environmental keywords i.e. they give information about the current environment, and the data model can't give that environmental info, this is what breaks it.

Why it seems to work in PQ for Excel I have no idea.

 

You could possibly try @'ing Ehren into this thread if you need the technicals on it.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Ehren
Microsoft Employee
Microsoft Employee

For perf reasons, in PBIDesktop refresh, we trim any queries that aren't being referenced (directly or indirectly) from the mashup document and replace them with a null value. References by name via #sections or #shared don't count, so they get turned into null.

Thanks. I guess that's only for PBI Desktop and not for Excel. I don't suppose there is any way to bypass that behavior for particular queries in PBI Desktop?

Ehren
Microsoft Employee
Microsoft Employee

No, I'm not aware of any way to bypass this behavior in PBIDesktop.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.