Forum Discussion

gvg's avatar
gvg
Post Prodigy
8 years ago
Solved

Invoking custom function from within a query

Hi all,

 

I don't seem to find correct syntax to invoke my custom function from a query. I have this function called xReplace that changes a lot of strings into something else. The function has no parameters - I simply need to place (get executed) instructions of the function so that I do not have to type them again in every query.

 

(mySource) =>
let
    #"Replaced Value" = Table.ReplaceValue(mySource,"ABC","123",Replacer.ReplaceText,{"ProductID"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value","DDD","456",Replacer.ReplaceText,{"ProductID"})
 
in
    #"Replaced Value2"

I am trying to do it like this, but Power BI complains, that it cannot convert a value of type Table to type List.

 

let
    Source = ....
    my = Function.Invoke(xReplace,#"Renamed Columns")
in
    my

Any ideas what am I doing wrong here?

  • Function.Invoke expects a list as second argument.

    It should be OK if you put the argument between curly brackets.

     

    let
        Source = ....
        my = Function.Invoke(xReplace,{#"Renamed Columns"})
    in
        my

     

    Otherwise you might consider not to use Function.Invoke and just call the function directly.

    I don't think Function.Invoke has any added value in this case.

5 Replies

  • MarcelBeug's avatar
    MarcelBeug
    Community Champion

    Function.Invoke expects a list as second argument.

    It should be OK if you put the argument between curly brackets.

     

    let
        Source = ....
        my = Function.Invoke(xReplace,{#"Renamed Columns"})
    in
        my

     

    Otherwise you might consider not to use Function.Invoke and just call the function directly.

    I don't think Function.Invoke has any added value in this case.

      • gvg's avatar
        gvg
        Post Prodigy

        MarcelBeug wrote:

        By the way, for multiple replacements you might consider using List.Accumulate.



        I understand this is to change individual characters. I need to change the whole phrases.

    • gvg's avatar
      gvg
      Post Prodigy

      Great, thanks! How do I call function directly? I thought I should use Invoke?