Forum Discussion

paulvans182's avatar
paulvans182
Helper III
6 years ago
Solved

Invoke Function: Reference Query using Query name as parameter

Good morning, 

 

I am busy experimenting with invoking functions in Power BI. I am trying to find a method of Referencing a Query using Invoked Functions.

 

I thought I could use the following:

 

 

= (strQueryName, strFieldName) =>

let
    Source = strQueryName
in
    Source

 

 

the strFieldName is a field in said query... and once I am able to reference said query I can begin using it.

 

However, when I attempted to use this code - it treated the strQueryName as Text - and so the function simply returns the text of the parameter.  Is there a data type I need to set the parameter to correctly reference the query?

 

Thank you for any help that can be provided

 

Kind regards,

Paul

  • Hi paulvans182 

     

    Sorry, probably misunderstood the original requirement.

    try this

    = ( strQueryName as table ) =>
    let
        Source = strQueryName 
    in  
        Source

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn

     

6 Replies

Replies have been turned off for this discussion
  • Mariusz's avatar
    Mariusz
    Community Champion

    Hi paulvans182 

     

    Sorry, probably misunderstood the original requirement.

    try this

    = ( strQueryName as table ) =>
    let
        Source = strQueryName 
    in  
        Source

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn

     

      • Mariusz's avatar
        Mariusz
        Community Champion

        Hi paulvans182 

         

        No problem at all.

         

         

        Best Regards,
        Mariusz

        If this post helps, then please consider Accepting it as the solution.

        Please feel free to connect with me.
        LinkedIn


         

    • nfuids's avatar
      nfuids
      New Member

      I have a very similar situation, but instead of trying to reference a query/table, I want to reference a Parameter defined in my PowerBI file (not a function parameter).

      So I basically have a parameter that
      TrainA = "ID OF TRAIN A"
      TrainB = "ID OF TRAIN B"

      and I would like to be able to tell which of the 2 parameters should my function use. 
      like 
      myTable = CallMyFunction("TrainA"). Inside my function, I do NOT want the text "TrainA" but rather the ID of train A.

      I dont see a parameter type of "parameter" as you proposed with the table type. Any way around this?

    • paulvans182's avatar
      paulvans182
      Helper III

      Hi Mariusz ,

       

      Thank you for the suggestion - however, unless i am misunderstanding, your solution appears to add a new column to the already existing table.

       

      What I am looking to do, is to create a new query with the same data as the existing query (essentially a duplicate or reference of the query) that I can then manipulate separately.  So, effectively I would have your original Table query, and a new query that looks identical to Table after I invoke the function using the queries name, "Table" as the parameter.

       

      Does that make sense?  Thanks again for any help you can provide 

       

      Kind regards,

       

      Paul