Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
smpa01
Super User
Super User

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

smpa01_0-1639081608527.png

 

smpa01_1-1639081637102.png

what is the workaround here?

 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
parry2k
Super User
Super 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?

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
AlexisOlson
Super User
Super 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 )

 

parry2k
Super User
Super 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?

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  It worked mate !!! thanks a lot.

 

It was a very small part of a very useful huge calcuation and pieces are aligining.

 

Thanks again. 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
smpa01
Super User
Super User

@AlexisOlson @parry2k @CNENFRNL @OwenAuger 

Need to bump this one up.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
az38
Community Champion
Community Champion

Hi @smpa01 

Maybe it's better to use ROW() instead of DATATABLE()?

VAR x = CROSSJOIN( ROW("column1",first),ROW("column2",second) )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38  Wow !!! very elegant !!! Thanks

 

I do have a follow up Q

 

If

VAR a = {"a","b","c"}

VAR b = {"e", "f","g"}

 

How can I still achieve the end goal without manually writing a ROW reference cause VAR a and VAR b are getting dynamically generated

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors