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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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!




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?

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors