Forum Discussion

gvg's avatar
gvg
Post Prodigy
6 years ago
Solved

Dynamic source table name in Power Query

Hi,

I have two data sources as tables in my query list: tableA and tableB. I want to build another query (myQuery) that dynamically takes either tableA or tableB as source. I know how to use parameters, but my problem is that I can not figure out how to specify the variable part (A or B) in my Source instruction in myQuery in "M". Tried this one, but it doesn't seem to work:

Source="table" & parameter1              //  parameter1 is ="A" or "B"

 

Can anybody help?

 

13 Replies

  • avatorl's avatar
    avatorl
    Impactful Individual
    = if your_parameter="A" then TableA else if your_parameter="B" then TableB else null

    you can use simple if statement

    • gvg's avatar
      gvg
      Post Prodigy

      OK. But then I am stuck with amending the code every time another table (tableC, etc.) arrives.

      • avatorl's avatar
        avatorl
        Impactful Individual

        gvg

        Source = Expression.Evaluate("Table" & parameter, #shared)