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
You're welcome 🙂
Thanks for the additional info.
The key thing is that the interface is set up so that "Convert to Parameter" option is only enabled for "literal" values, i.e. hard-coded numbers, date, text etc.
Even if the result of your query is a single text value, if it is not a literal text value, "Convert to Parameter" is not available.
So the only way to create a dynamic parameter is to add the metadata as I showed in the previous post.
Thanks for the clarification!