简体   繁体   English

Power BI - 累积总和

[英]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).我有一些可以应用的过滤器(如城市、部门、ID 和时间段)。 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).当我尝试添加过滤器时,我的编码要么返回错误,要么返回从过滤的时间段开始的累积总和:例如,假设我在 1 月、2 月、3 月和 4 月为 A 城市设置了 10 的值,B 部门。如果我选​​择显示三月和四月的值,它应该显示 30 和 40。但是,当前图表显示过滤时间段的累积值(并且会显示 10 和 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.我曾尝试仅使用来自 TableA 的数据,并尝试使用 TableB 作为独立的时间段表。 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. ALL(Table)将强制度量忽略时间段过滤器。

To keep your additional parameters, you'll probably want to use ALLEXCEPT .要保留其他参数,您可能需要使用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"
            )
         )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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