Forum Discussion

AspasiaLiz's avatar
AspasiaLiz
Frequent Visitor
2 years ago
Solved

Convert to Parameter Greyed Out

Hi, I'd like to pull Odata Web Services from Business Central - Item Ledger Entry table but I want to pull last 12 months so that it doesn't take forever to pull. I have created a table and mad...
  • OwenAuger's avatar
    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_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