简体   繁体   中英

Power BI - Cumulative sum

I need to show the cumulative value of a sum of some columns, but I need to merge the cumulative sum with some filters aswell.

I have some filters that can be applied (like City, Department, id, and time period). For example, this code works:

Cumulative_sum = CALCULATE( SUM(Table[ColumnA]) + SUM(Table[ColumnB]) + SUM(Table[ColumnC]); FILTER(ALL(Table(TIME_PERIOD); Table[TIME_PERIOD] <= MAX (Table[TIME_PERIOD])))

When I tried to add the filter, my coding either returns an error or returns the cumulative sum starting on the time period filtered: For example, let's say I have a value of 10 in January, Feb, March, and April for the city A, department B. If I choose to show the values of March and April, it should show 30 and 40. However, the current graph shows the cumulative value of the filtered time period (and would show 10 and 20).

Here is what Im trying:

   Cumulative_sum = CALCULATE( SUM(TableA[ColumnA]) + SUM(TableA[ColumnB]) + SUM(TableA[ColumnC]); FILTER(ALL(TableB(TIME_PERIOD); TableB[TIME_PERIOD] <= MAX (TableB[TIME_PERIOD])); FILTER(ALLSELECTED(TableA); TableA

[SITUATION] = "OK'))

I have tried using the data only from TableA, and tried using TableB as a Time Period table independent. Whats my mistake here?

Try this:

Cumulative_sum =
    CALCULATE(
        SUM(Table[ColumnA]) + SUM(Table[ColumnB]) + SUM(Table[ColumnC]);
        FILTER(ALL(Table);
            Table[TIME_PERIOD] <= MAX(Table[TIME_PERIOD]) &&
            Table[SITUATION] = "OK"
            )
         )

The ALL(Table) will force the measure to ignore the time period filter.

To keep your additional parameters, you'll probably want to use ALLEXCEPT .

Cumulative_sum =
    CALCULATE(
        SUM(Table[ColumnA]) + SUM(Table[ColumnB]) + SUM(Table[ColumnC]);
        FILTER(ALLEXCEPT(Table, Table[City], Table[Department], Table[ID]);
            Table[TIME_PERIOD] <= MAX(Table[TIME_PERIOD]) &&
            Table[SITUATION] = "OK"
            )
         )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM