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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
mp390988
Post Patron
Post Patron

SUMX with CALCULATETABLE inside

Hello,

 

I understand context transition happens when we have calculate/calculatetable or a named measure inside an interator. For example, if I create a calculated column and enter this formula =CALCULATE(SUMX(Table1, Table1[Field1]*Table1[Field2]) then I know the current row in the calculated column gets passed on as filter when the SUMX scans Table1 and we should see different values in each row in the calculated column.

However, I don't understand what exactly happens when we create a calculate column that contains a CALCULATETABLE inside SUMX? For example, this is my formula inside the calculated column:

calculated column=SUMX(

CALCULATETABLE(Orders, Orders[Freight]>100, Orders[ShipVia]=3),

Orders[Freight])
)

This formula then creates the below output. As you can see, we have distinct values appearing only in rows where the Freight > 100 and the ShipVia = 3. 

 

mp390988_1-1685697409539.png

 

I was expecting to see repeated values in all rows because the SUMX is not wrapped around CALCULATE. For example, when we have something like calculated column = SUMX(Products, Products[Price]*Products[Qty]) we get the same repeated values down the column but if we wrap this formula inside CALCULATE we get a unique value for each row. So the question is, why does my above formula when its not wrapped inside a CALCULATE is still giving distinct values only for when Frieght > 100 and ShipVia=3.

 

Thank You in advance.




1 ACCEPTED SOLUTION
johnt75
Super User
Super User

CALCULATETABLE is forcing context transition, so the current row essentially becomes the filter context. The filters on Freight and Ship Via then get merged into that context, so you are only seeing values for rows which match the Freight and Ship Via conditions. It is equivalent to writing

calculated column =
IF ( Orders[Freight] > 100 && Orders[ShipVia] = 3, Orders[Freight] )

View solution in original post

2 REPLIES 2
mp390988
Post Patron
Post Patron

Cheers!

johnt75
Super User
Super User

CALCULATETABLE is forcing context transition, so the current row essentially becomes the filter context. The filters on Freight and Ship Via then get merged into that context, so you are only seeing values for rows which match the Freight and Ship Via conditions. It is equivalent to writing

calculated column =
IF ( Orders[Freight] > 100 && Orders[ShipVia] = 3, Orders[Freight] )

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.