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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
bcdobbs
Community Champion
Community Champion

DAX Expanded Table Filtering Requiring two CALCULATETABLE statements

Hi,
I have a data model as shown here:

bcdobbs_0-1622992043516.png

 

There is a basic measure that counts number of tickets:

Number of Tickets = COUNTROWS(Tickets)

 

I wrote a measure that works fine to calculate the average number of tickets per event.
Requirement was that the denominator of the average (number of events) needed to only respond to filters on organiser, venue and event. Eg if a filter was applied to TicketClass or TicketStatus the number of events remained unaffected.

VAR EventIdTable =
    CALCULATETABLE (
        VALUES ( Events[EventId] ),
        CROSSFILTER ( Events[EventId], Tickets[EventId], BOTH ),
        ALLEXCEPT ( Tickets, Events, Organisers, Venues )
    )
VAR Result =
    AVERAGEX (
        EventIdTable,
        IF.EAGER ( ISBLANK ( [Number of Tickets] ), 0, [Number of Tickets] )
    )
RETURN
    Result

 

However having read the chapter on expanded tables in the definitive guide to DAX I tried the following:

VAR EventIdTable =
    CALCULATETABLE (
        VALUES ( Events[EventId] ),
        Tickets,
        ALLEXCEPT ( Tickets, Events, Organisers, Venues )
    )
VAR Result =
    AVERAGEX (
        EventIdTable,
        IF.EAGER ( ISBLANK ( [Number of Tickets] ), 0, [Number of Tickets] )
    )
RETURN
    Result

Having played with it in DAX studio it became clear that ALLEXCEPT wasn't removing filters from TicketClass or TicketStatus tables.  I was able to make it work putting a second CALCUALTETABLE in as follows:

VAR EventIdTable =
    CALCULATETABLE (
        CALCULATETABLE ( VALUES ( Events[EventId] ), Tickets ),
        ALLEXCEPT ( Tickets, Events, Organisers, Venues )
    )
VAR Result =
    AVERAGEX (
        EventIdTable,
        IF.EAGER ( ISBLANK ( [Number of Tickets] ), 0, [Number of Tickets] )
    )
RETURN
    Result

 

Hoping someone can help explain what is happening with the filter contexts here that requires an outer CALCULATETABLE.

 

Thanks

 

Ben



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @bcdobbs 

Can you share the pbix?

In the first version:

VAR EventIdTable =
    CALCULATETABLE (
          VALUES ( Events[EventId] ),
          Tickets,
          ALLEXCEPT ( Tickets, Events, Organisers, Venues )
)

 

Tickets carries your filter context, including filters on TicketClass and TicketStatus. Even though your last argument clears those TicketClass, TicketStatus filters, you're throwing them right back in in your second argument. Remember that every filter argument is evaluated in the original filter context independently (i.e. it is not affected by any other modifier or filter argument within that Calculate). Then the new filter context is built as an AND of all the filter arguments. This is the crux to the behaviour you are seeing.

 

In the second version, you're feeding the inner calculate with a filter context that has TicketClass, TicketStatus cleared. 

 VAR EventIdTable =
CALCULATETABLE (
       CALCULATETABLE ( VALUES ( Events[EventId] ), Tickets ),
       ALLEXCEPT ( Tickets, Events, Organisers, Venues )
)

Tickets thus has, as a result, TicketClass and TicketStatus cleared. It is then applied to the first argument in the inner calculate.  

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @bcdobbs 

Can you share the pbix?

In the first version:

VAR EventIdTable =
    CALCULATETABLE (
          VALUES ( Events[EventId] ),
          Tickets,
          ALLEXCEPT ( Tickets, Events, Organisers, Venues )
)

 

Tickets carries your filter context, including filters on TicketClass and TicketStatus. Even though your last argument clears those TicketClass, TicketStatus filters, you're throwing them right back in in your second argument. Remember that every filter argument is evaluated in the original filter context independently (i.e. it is not affected by any other modifier or filter argument within that Calculate). Then the new filter context is built as an AND of all the filter arguments. This is the crux to the behaviour you are seeing.

 

In the second version, you're feeding the inner calculate with a filter context that has TicketClass, TicketStatus cleared. 

 VAR EventIdTable =
CALCULATETABLE (
       CALCULATETABLE ( VALUES ( Events[EventId] ), Tickets ),
       ALLEXCEPT ( Tickets, Events, Organisers, Venues )
)

Tickets thus has, as a result, TicketClass and TicketStatus cleared. It is then applied to the first argument in the inner calculate.  

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

bcdobbs
Community Champion
Community Champion

That makes perfect sense. Simple when you put it like that! Thank you.

 

Simplified version of the PBIX file attached (orginal was running direct on EventBrite API so had to cut it down:
PBIX Example 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.