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
lbendlin
Super User
Super User

Can I use a table variable inside a table variable?

This has been bugging me for a while.

 

Why can I do this:

 

var wd = SELECTCOLUMNS(Filter(Dates,Dates[StartOfMonth]=Sick[Month] && Dates[IsWeekDay]=TRUE()),"Date",Dates[Date])
var ab= SUMMARIZE(Filter(Absence,Absence[LongTerm]=Sick[LongTerm]),Absence[Personnel Number],Absence[Start Date],Absence[Actual End Date])
var ab1=ADDCOLUMNS(ab,"d",COUNTROWS(INTERSECT(CALENDAR(Absence[Start Date],Absence[Actual End Date]),wd)))

 

 

but not this:

 

var wd = SELECTCOLUMNS(Filter(Dates,Dates[StartOfMonth]=Sick[Month] && Dates[IsWeekDay]=TRUE()),"Date",Dates[Date])
var ab= SUMMARIZE(Filter(Absence,Absence[LongTerm]=Sick[LongTerm]),Absence[Personnel Number],Absence[Start Date],Absence[Actual End Date],"Cal",CALENDAR(Absence[Start Date],Absence[Actual End Date]))
var ab1=ADDCOLUMNS(ab,"d",COUNTROWS(INTERSECT([Cal],wd)))

 

 

or more generic

 

var tablevariable1 = SUMMARIZE(table,column1,column2,"new column",tablevariable2)
var tablevariable3 = ADDCOLUMNS(tablevariable1,"Count",COUNTROWS([tablevariable2]))

 

 

i need to walk up and down a multidimensional hierarchy and do aggregrations between the hierarchies. That requires temporarily storing tables in fields of the parent table, and then retrieving the child tables again for processing.

 

So far the only option I can see is to do a fully explicit table processing without the possibility of storing the table variable for later retrieval.  Is that a DAX design limitation or am I using the wrong syntax? This is very easy to do in Power Query, so I hope that I'm just overlooking something obvious.

1 REPLY 1
Stachu
Community Champion
Community Champion

you can use the table variables within the table expression, but the syntax has to be valid, which in your case is not possible with SUMMARIZE

the issue is here:

VAR ab =
    SUMMARIZE (
        FILTER ( Absence, Absence[LongTerm] = Sick[LongTerm] ),
        Absence[Personnel Number],
        Absence[Start Date],
        Absence[Actual End Date],
        "Cal", CALENDAR ( Absence[Start Date], Absence[Actual End Date] )
    )

SUMMARIZE requires last argument to be scalar expression, CALENDAR returns table, which makes the syntax invalid and causes error.

 

the reason it works for

VAR ab =
    SUMMARIZE (
        FILTER ( Absence, Absence[LongTerm] = Sick[LongTerm] ),
        Absence[Personnel Number],
        Absence[Start Date],
        Absence[Actual End Date]
    )
VAR ab1 =
    ADDCOLUMNS (
        ab,
        "d",
            COUNTROWS (
                INTERSECT ( CALENDAR ( Absence[Start Date], Absence[Actual End Date] ), wd )
            )
    )

is that the result of CALENDAR is only evaluated in memory when caclulating the scalar value - no need for "materialized" nested tables



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.