none
Reference a query or a query function by its name RRS feed

  • Question

  • Hi ,

    Let's define for example a query named qryTest as

            let

                   result=Text.Combine({"Hello ", "World"])

            in

                   result

    Now, define a new query named Test as

    let

      txtVariable="qryTest",

    .....

    Can I reference the query qryTest by the txtVariable inside the query Test?

    Thanks in advance 

    Alb3Vi

    Friday, December 15, 2017 2:20 PM

Answers

  • If AA and bb are query function names or query names, they must NOT be in double quotes, but written like so:

    let
        AA= XP_DECODE_SIRE_CCY,
        bb= XP_GET_REFERENCE_DATE,


    Imke Feldmann - MVP Data Platform (PowerBI) - http://www.TheBIccountant.com 

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful - Thanks!

    Thursday, December 21, 2017 6:27 AM
    Moderator

All replies

  • Yes, you can do it. Just omit the double quotes:

    let

      txtVariable= qryTest ,

    .....


    Imke Feldmann - MVP Data Platform (PowerBI) - http://www.TheBIccountant.com 

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful - Thanks!

    Friday, December 15, 2017 7:06 PM
    Moderator
  • Hi Imke, 

    thank you for your repla but I would like to use txtVariable as un user input (parametre) written in a excel cell so it must be text type... The idea is to "replicate" the excel function INDIRECT; refers to a query/query functon by its text name

    Regards

    Monday, December 18, 2017 10:05 AM
  • Then you can use Expression.Evaluate like this:

    txtVariable = Expression.Evaluate("qryTest", #shared)


    Imke Feldmann - MVP Data Platform (PowerBI) - http://www.TheBIccountant.com 

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful - Thanks!

    Monday, December 18, 2017 10:14 AM
    Moderator
  • Hi Imke,

    that was my first idea but it works only if I open the advanced editor. Othwerwise I get the error "qryTest doesn't exists in the current context" 

    Regards

    Tuesday, December 19, 2017 11:12 AM
  • Sorry, but I don't understand what you mean here.

    Could you please paste your full code where it doesn't work?


    Imke Feldmann - MVP Data Platform (PowerBI) - http://www.TheBIccountant.com 

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful - Thanks!

    Tuesday, December 19, 2017 11:31 AM
    Moderator
  • let
        AA="XP_DECODE_SIRE_CCY",
        bb="XP_GET_REFERENCE_DATE",
        setLib=[],
        MyLibrary0 =Record.AddField(setLib, AA, Expression.Evaluate(AA, #shared)),
        MyLibrary1 =Record.AddField( MyLibrary0, bb, Expression.Evaluate(bb, #shared)),
        MyLibrary=Record.Combine({MyLibrary1,#shared})   
    in
      MyLibrary

    where XP_DECODE_SIRE_CCY and XP_GET_REFERENCE_DATE are, for example, a query function name and a query name respectively.

    If I execute this let expression inside the advanced query editor it's OK otherwise I get the following error

    "Expression.Error: the name "XP_DECODE_SIRE_CCY" doesn't exist in the current context"

    

    Tuesday, December 19, 2017 11:49 AM
  • If AA and bb are query function names or query names, they must NOT be in double quotes, but written like so:

    let
        AA= XP_DECODE_SIRE_CCY,
        bb= XP_GET_REFERENCE_DATE,


    Imke Feldmann - MVP Data Platform (PowerBI) - http://www.TheBIccountant.com 

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful - Thanks!

    Thursday, December 21, 2017 6:27 AM
    Moderator