问题
I would like to use a PowerQuery Formula which includes input from a text box like
Json.Document(Web.Contents("https://thesite.com/api/widgets",
[Query=[name=TextBoxName.Text]]))
But I get this error
Expression.Error: The import TextBoxName.Text matches no exports. Did
you miss a module reference?
How do I use TextBoxName.Text as a parameter in my query?
回答1:
Does it have to be a text box? Put the value in an Excel table instead and call that table "Parameters".
Then write a function that reads the parameters in the table.
(ParameterName as text) =>
let
ParamSource = Excel.CurrentWorkbook(){[Name="Parameters"]}[Content],
ParamRow = Table.SelectRows(ParamSource, each ([Parameter] ParameterName)),
Value=
if Table.IsEmpty(ParamRow)=true
then null
else Record.Field(ParamRow{0},"Value")
in
Value
Give that function the name fnGetParameter and load it.
Now you can use this function in another query to get the value of any parameter in the table like this:
let
MyQuery = fnGetParameter("JSONQuery"),
Source = Json.Document(Web.Contents("https://thesite.com/api/widgets",
[Query=[name=MyQuery]]))
Credit goes to Ken Puls who describes this technique on his blog and also in his book "M is for (Data) Monkey".
来源:https://stackoverflow.com/questions/34027392/how-can-i-use-input-from-a-textbox-in-a-powerquery-formula