Forum Discussion
Convert to Parameter Greyed Out
- 2 years ago
Hi AspasiaLiz
The "Convert to Parameter" option in the interface is only available for values that are a "simple non-structured constant" (see here).
In your case, if FromDate and ToDate are more complex queries, you would have to edit the code in the Advanced Editor and add appropriate metadata to turn these into parameters.
For example, if ToDate is defined as:
let TodayDate = Date.From(DateTime.FixedLocalNow()), DateEnd_Date = Date.EndOfMonth(Date.AddMonths(TodayDate,-1)), DateEnd_Text = Date.ToText(DateEnd_Date, "yyyy-MM-dd") in DateEnd_Textthen you can convert it to a parameter by editing the code as follows, wrapping in brackets and adding meta [...]:
( let TodayDate = Date.From(DateTime.FixedLocalNow()), DateEnd_Date = Date.EndOfMonth(Date.AddMonths(TodayDate,-1)), DateEnd_Text = Date.ToText(DateEnd_Date, "yyyy-MM-dd") in DateEnd_Text ) meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=false]I suggest specifying IsParameterQueryRequired = false otherwise the interface shows an error in certain places.
As a side note, if another query is referencing FromDate or ToDate, it shouldn't matter whether or not they are parameters, as the value will still be the same.
See Ben Gribaudo's blog for more detail on metadata:
https://bengribaudo.com/blog/2021/03/17/5523/power-query-m-primer-part20-metadata
Does the above help with what you're doing?
Regards
Hi AspasiaLiz
The "Convert to Parameter" option in the interface is only available for values that are a "simple non-structured constant" (see here).
In your case, if FromDate and ToDate are more complex queries, you would have to edit the code in the Advanced Editor and add appropriate metadata to turn these into parameters.
For example, if ToDate is defined as:
let
TodayDate = Date.From(DateTime.FixedLocalNow()),
DateEnd_Date = Date.EndOfMonth(Date.AddMonths(TodayDate,-1)),
DateEnd_Text = Date.ToText(DateEnd_Date, "yyyy-MM-dd")
in
DateEnd_Text
then you can convert it to a parameter by editing the code as follows, wrapping in brackets and adding meta [...]:
(
let
TodayDate = Date.From(DateTime.FixedLocalNow()),
DateEnd_Date = Date.EndOfMonth(Date.AddMonths(TodayDate,-1)),
DateEnd_Text = Date.ToText(DateEnd_Date, "yyyy-MM-dd")
in
DateEnd_Text
)
meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=false]
I suggest specifying IsParameterQueryRequired = false otherwise the interface shows an error in certain places.
As a side note, if another query is referencing FromDate or ToDate, it shouldn't matter whether or not they are parameters, as the value will still be the same.
See Ben Gribaudo's blog for more detail on metadata:
https://bengribaudo.com/blog/2021/03/17/5523/power-query-m-primer-part20-metadata
Does the above help with what you're doing?
Regards
This is fantatsic solution.