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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Advocate II
Advocate II

Make a shared query use another query as input (fix "may not directly access a data source" error)

Hi guys,


We know that when a query cannot simultaneously access an external data source (external files, excel tables, etc.) and another query from the power query list (power query editor).


Doing so will raise the "...may not directly access a data source" error.


However this limitation is ridiculous, especially for shared queries. By shared I mean queries that are stored in text files and called with code such as:

(TargetTable as table, TargetCol as text, LookupTable as table, LookupOldCol as text, LookupNewCol as text) =>
  GetFunction = Text.FromBinary(File.Contents(Excel.CurrentWorkbook(){[Name="PQMacrosFolder"]}[Content]{0}[Column1]&"GetCSVByDateAndName.txt")),
EvaluateFunction = Expression.Evaluate(GetFunction, #shared),
EvaluateFunction2 = EvaluateFunction(TargetTable, TargetCol, LookupTable, LookupOldCol, LookupNewCol)

Shared queries by definition are referring to an external data source (the text file). So then how can I use a shared query that will act on another query? This need is very realistic. Imagine you wrote a PQ macro that modify a table (a query) in some way. Now you wanna store it in a central location to re-use (in the same way you store VBA macros in xlam file). However this is never possible with the current power query architecture.


Anybody has a work-around?


ImkeF @v-juanli-msft @Nolock @exmrsjones ?

Resolver II
Resolver II

Hi @freelensia,


As I understand your question you want all the queries to be stored in one central location so that it can be re-used multiple times?


According to me, there are two ways to do this. 


1. Custom function: you can create custom functions and then it can be re-used in other queries

2. Data Flows: this is like, Power Query on the cloud. Where anyone within the organisation can use this.


Hope that answers your question



Pradip Microsoft Certified Trainer

Pradip's YouTube Channel

Thanks for the quick answer.

1. Yes I have created custom functions. However they can only be used in one Excel workbook, not multiple.

2. Data flows are not free, am I correct?


If so, these 2 suggestions do not solve my issue.

Hi @freelensia 


I though you're working in Power BI. Data flows only available in Power BI cloud. I am sorry i ran out of suggestions.



Pradip Microsoft Certified Trainer

Pradip's YouTube Channel

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.

Top Solution Authors
Top Kudoed Authors