Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

powerbi - How does CALCULATE, SUM, MAX and <= logically work for cumulative total?

Cumulative Total =
CALCULATE (
    SUM ( Table[Value] ),
    FILTER (
        ALL ( Table[Index] ),
        Table[Index]
            <= MAX ( Table[Index] )
    )
)

I'm trying to understand how the above formula logically works.

1st the CALCULATEs 2nd parameter gets evaluated. The 2nd param returns a filtered table containing a single column.

In the FILTER the 1st param removes any filter from the index column. The 2nd param of filter checks that the index should be less than or equal to max from outer table.

But how does the CALCULATEs SUM do cumulative? Does FILTER work for each record of the SUM?

question from:https://stackoverflow.com/questions/65856716/how-does-calculate-sum-max-and-logically-work-for-cumulative-total

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

FILTER is an iterator, CALCULATE is not. In this formula FILTER returns a table with a single column, 'Table'[Index], containing all of the Indexes that are less or equal to the MAX( 'Table'[Index] ) evaluated in the filter context existing when CALCULATE is executed.

When SUM( 'Table'[Value] ) is evaluated inside CALCULATE, the filtered table evaluated in the previous step is applied as filter context. This replaces any filter context existing on the same column, but is combined with possible other filter existing on other columns.

These filters are applied on Table and only the rows satisfying these criteria will be iterated by the SUM.

So it is not CALCULATE that iterates over Table. And SUM iterates on Table already filtered by the filter contex modified by CALCULATE.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...