How to accomodate different database / schema names when writing M queries in Power BI?
I am working with Power BI and I need to setup a template with some input parameters, one of them being the name of the database to get data from.
To do this, I have setup a parameter (called project_database) so that users can specify the database to be used in an Query via the Parameter Manager in Power Query Editor.
I wrote a M Query that collects data from a database like so (with project_database being the input parameter):
let
Source = MySQL.Database("127.0.0.1", project_database, [ReturnSingleDatabase=true]),
working = Source{[Schema=project_database,Item="example_table"]}[Data],
in
working
The problem is, this query will generate a result table with all the generated column names being based off of the actual database name (what project_database resolves to.)
For example, if the database name was xyz, the generated column names would be xyz.id, xyz.fielda, xyz.fieldb etc...)
How do I properly reference columns throughout the M query if I cannot rely on the schema portion of their names remaining consistent, since Power BI generates them based off of the schema name?
I attempted referencing the column names by
project_database ".field"
But this is insanely tedious to do throughout the every M query. There must be a better approach?
Thanks!
Topic powerbi
Category Data Science