I need to return a set of data from a database based on a parameter that is in excel.
So I have created the following 'Query1'
let
Source = Sql.Database("VI107064\SQLEXPRESS", "Stock", [Query="select * from customer#(lf)where custID = " &CustID])
in
Source
Then I created the 'CustID'
let
Source = Excel.CurrentWorkbook(){[Name="CustID"]}[Content],
SourceValue = Record.Field(Source{0}, "CustID"),
SourceText = Number.ToText(SourceValue)
in
SourceText
The issue is that Excel is complaining that the query refernces other queries or steps, so it may not directly access a datasource Please rebuild this data combination.
So after reading https://www.excelguru.ca/blog/2015/03/11/power-query-errors-please-rebuild-this-data-combination/
I understood the issue, and I think for me to fix the problem, I need to duplicate query1 to query2. Update query 1 so that it just returns the table. Update query 2 so that it takes query 1 as a source and then adds the filter.
Is that correct? or is there a better way to do this?