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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
migueljoa
Frequent Visitor

Evaluation Context LOGIC on Running Total

 

The standard DAX expression for Running total is:

 

Cumulative Quantity :=
CALCULATE (
    SUM ( Transactions[Quantity] ),
    FILTER (
        ALL ( 'Date'[Date] ),
        'Date'[Date] <= MAX ( 'Date'[Date] )
    )
)
 
And usually you have a pivot with ITEMID and DATE on the horizontal/vertical axis. These two provide FILTER CONTEXT.
 
This might be a dumb question but how is 'Date'[Date] <= MAX ( 'Date'[Date] ) working?

I have read some books about the DAX engine, and I know that FILTER is an ITERATOR which generates a ROW CONTEXT, but then ALL overrides the FILTER CONTEXT on Dates coming from the pivot, thus my understanding is that MAX ( 'Date'[Date] ), being in a ROW CONTEXT, should be returning the maximun date from the whole Date Table, meaning that the FILTER clause always return the full date table.
 
My logic is flawed since for this formula to work, MAX ( 'Date'[Date] ) must consider the FILTER CONTEXT coming from the pivot on Dates (that's what I guess), but I don't understand how or why?
 
What am I missing? 
1 ACCEPTED SOLUTION

@migueljoa

 

You are perfectly correct....

 

Following is taken from Rob Collie and Avi Singh's famous book on Power BI

 

context.jpg


Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

Hi @migueljoa

 

MAX/Sum/Avg....any aggregation formulas always refer to FILTER Context.....

The only filter context that is available is from the Pivot table in your Case. So it takes the row value.....(You can use SELECTEDVALUE as well)

However if you wrap the aggregation inside Calculate function then the ROW context created by FILTER function will be transformed into FILTER context....and the filter context from the pivot would be ignored.

 

 


Regards
Zubair

Please try my custom visuals

Hi @Zubair_Muhammad

So the Filter Context of the Pivot table is used on the MAX function because all aggregations are evaluated on a Filter Context? And ALL(Dates) overrides the filter context but only for the table that is FILTERED?

Thanks! I appreciate very much the time you have taken to answer my doubts

@migueljoa

 

You are perfectly correct....

 

Following is taken from Rob Collie and Avi Singh's famous book on Power BI

 

context.jpg


Regards
Zubair

Please try my custom visuals

I see... I must have missed that part of the reading. Everything is crystal clear now!

Thanks for putting it out for me. Greatly appreciate it!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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