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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.