Forum Discussion
Constructing table in Dax from Variables
I am trying to figure out how can I end with a table from at least two variables
My code is following
Table =
VAR first = "a"
VAR second = "b"
VAR x= CROSSJOIN(DATATABLE("column1",STRING,{{first}}),DATATABLE("column2",STRING,{{second}}))
VAR y = CROSSjoin({first},{second})
RETURN _y
I want to end up with a table containg two columns with a and b that is quivalent of what the following can do
DATATABLE("first",string,"second",string,{{"a","b"}})
I can't get to where I need to as it is generating the following error in both instances
what is the workaround here?
smpa01 Not sure if this is what you are looking for? You can do crossjoin these two variables and rename the column name, or use selectcolumns and then cross join
Table = VAR a = {"a","b","c"} VAR b = {"e", "f","g"} RETURN CROSSJOIN ( SELECTCOLUMNS ( a, "First", [Value] ), SELECTCOLUMNS ( b, "Second", [Value] ) )or you want row 1 of each table to join and then row 2 to row 2 and so on...
what is your end goal?
6 Replies
- parry2kSuper User
smpa01 Not sure if this is what you are looking for? You can do crossjoin these two variables and rename the column name, or use selectcolumns and then cross join
Table = VAR a = {"a","b","c"} VAR b = {"e", "f","g"} RETURN CROSSJOIN ( SELECTCOLUMNS ( a, "First", [Value] ), SELECTCOLUMNS ( b, "Second", [Value] ) )or you want row 1 of each table to join and then row 2 to row 2 and so on...
what is your end goal? - smpa01Community Champion
AlexisOlson parry2k CNENFRNL OwenAuger
Need to bump this one up.
- AlexisOlsonSuper User
In addition to CROSSJOIN, you can also use GENERATE or GENERATEALL.
Table = VAR a = { "a", "b", "c" } VAR b = { "e", "f", "g" } VAR aTbl = SELECTCOLUMNS ( a, "First", [Value] ) VAR bTbl = SELECTCOLUMNS ( b, "Second", [Value] ) RETURN GENERATE ( aTbl, bTbl )