Forum Discussion
Parameter changing datasource type DB2->ODBC
Hi,
I have this M code and trying to return the TABLE1 table for conditionally 2 datasources (ODBC and DB2) which has the same structure.
I'm not good at M: I think that the third row generates a parameter field, but I have yet created a parameter (called "parameter") as another datasource that I want to manage outside this code.
"parameter" is managed to have 2 pre-defined values selectable "ODBC" and "DB2".
For me, for a better understanding of the code structure, suppose that I also want to rename the field "LOREM" in "IPSUM".
let
#"Origine" = (para as text) =>
if para = "ODBC"
then
let
Source = Odbc.DataSource("dsn=dsnname", [HierarchicalNavigation=true])
in
Source
else
let
Source = DB2.Database("servername", "test", [Implementation="IBM"])
in
Source
in #"Origine" Anonymous
Thank you in advance!
Hi AGo,
in M, every query step can be seen as a variable. So your requirement can be solved like this:
let Odbc = Odbc.DataSource("dsn=dsnname", [HierarchicalNavigation=true]), DB2 = DB2.Database("servername", "test", [Implementation="IBM"]), Origine = if para = "ODBC" then Odbc else DB2 in Origine
3 Replies
- Greg_DecklerCommunity Champion
Invoking ImkeF
- ImkeFCommunity Champion
Hi AGo,
in M, every query step can be seen as a variable. So your requirement can be solved like this:
let Odbc = Odbc.DataSource("dsn=dsnname", [HierarchicalNavigation=true]), DB2 = DB2.Database("servername", "test", [Implementation="IBM"]), Origine = if para = "ODBC" then Odbc else DB2 in Origine- AGoPost Patron
Works like a charm! And thanks forthe functioning explaining.