Forum Discussion

hideakisuzuki01's avatar
3 years ago

Need help understanding Context Transition

Hi, 
I have below two tables (Fact and ProductDim) 

Fact  ProductDim 
ProductSales ProductSalesPerson
A100 AJames
A200 BChris
B300 CSteve
B400   
B500   
C600   

 

I want to add a calculated column in the ProductDim or measure that calculates total sales amount for each product.

 

Calculated Column1 ->   TotalSales1 = SUM('Fact'[Sales])

Calculated Column2 ->   TotalSales2 = CALCULATE(SUM('Fact'[Sales]))

Measure                    ->   TotalSales3Measure = SUM('Fact'[Sales])

 

When I use them in a table , the result is this

My question is, why is "TotalSales3Measure" calculates the sales amount correctly when there is no row context?  

Below is my understanding:

"TotalSales1" does not work correctly because there is no CALCULATE and so context transition does not occur.

"TotalSales2" works correctly because there is CALCULATE and row context (because its a calculated column) so context transition occurs. 

But in case of "TotalSales3Measure", there is an invisible CALCULATE(because its a measure) but there is no row context, right ?

So does context transition occur in this case ? 

 

 

 

2 Replies

  • No, measure 3 has a filter context.  Context transition takes a row context and converts it to a filter context.  Filter context is the more common context in models.  Row context comes in when you are iterating over a table (calculated columns, SUMX, AVERAGEX, etc)  and that is where you need the context trasition forced by CALCULATE or the hidden CALCULATE on an exising measure.

  • Thanks jd !
    Can you also tell me if I understand this correctly regarding "TotalSales2" ?

    "TotalSales2" works correctly, because there is a CALCULATE function, so it follows relationship between the two tables.

    And it follows the relationship because of context transition.
    Is this correct ?

     

    Or Context transition has nothing to do with following the relationship, and CALCULATE forces the table relationship active ?