Power BI累积减法

时间:2019-02-20 13:09:49

标签: powerbi dax

我有一个计算表,其中我将实际成本除以总成本然后乘以100得到百分比。

我每周都会这样显示此值:

Week 1 | Week 2 | Week 3 | Week 4
-------+--------+--------+-------
    70 |     80 |     60 |     90 

但我想这样更改它:

Week 1 | Week 2 | Week 3 | Week 4
-------+--------+--------+-------
    70 |     80 |     60 |     90 
       |     10 |    -20 |     30

当前我正在使用以下公式:

Percentage_weekly_confirmation_rate = DIVIDE([Accepted PO Cost], [Total PO Cost])

Accepted PO CostTotal PO Cost都是计算值。

我应该怎么做才能达到预期的效果?

1 个答案:

答案 0 :(得分:0)

我已通过以下简单的SELECT将Week和Confirmation_Rate字段加载到PBI文件中:

SELECT 'Week_1' AS [Week], 70 AS Confirmation_Rate
UNION ALL
SELECT 'Week_2' AS [Week], 80 AS Confirmation_Rate
UNION ALL
SELECT 'Week_3' AS [Week], 60 AS Confirmation_Rate
UNION ALL
SELECT 'Week_4' AS [Week], 90 AS Confirmation_Rate

这就是我如何计算您所需的内容:

Column = 
VAR PreviousRow =
    TOPN (
        1;
        FILTER(Table_1; Table_1[Week] < EARLIER ( Table_1[Week] ) );
        [Week]; DESC
    )
VAR PreviousValue =
    MINX ( PreviousRow; DIVIDE(Table_1[Confirmation_Rate]; 1) )
RETURN
    DIVIDE(Table_1[Confirmation_Rate]; 1) - PreviousValue

如果命名不同,请尝试将DIVIDE()函数中的参数替换为您的参数,并将Table_1 [Week]字段替换为我的参数。