本文介绍了我想要Power Bi中的脚本,该脚本将计算从一个月到上个月的百分比增加或减少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在选择每个月时显示每个月的总计增加或减少百分比,即当我单击FEB时,它应该告诉我与JAN相比,支出是否有增加/减少的百分比。

I want to display percentage increase or decrease in total for each month as I select each month i.e when I click on FEB, it should tell me whether there was a percentage increase/decrease in expenses compared to JAN.

我尝试了不同的代码,但不断收到错误消息。

I have tried different codes but keep getting an error message.

这是我尝试的DAX代码:

Here is a DAX CODE I tried:

change perc =
VAR ValueLastMONTH =
CALCULATE (
    SUM ( population[TOTAL] ),
    FILTER (
        population,
        population[MONTH]
            = ( EARLIER ( population[MONTH] ) - 1 )
            && population[CATEGORY] = EARLIER ( population[CATEGORY] )

    )
)
RETURN
IF (
    ISBLANK ( ValueLastMONTH ),
    0,
    ( population[TOTAL] - ValueLastMONTH )
        / ValueLastMONTH

我希望创建一个新列来显示从一个月到上个月的百分比增加或减少。
这是excel文档的屏幕截图:

I want a new column created to display the percentage increase or decrease from a month to its previous month.Here is a screenshot of the excel document:

推荐答案

月列的类型不是日期。 PowerBi如何知道APR代表四月的文字?

The Column 'Month' is not of type date. How would PowerBi know the text APR represents April? You need to make this column a date.

现在,您需要更改脚本以与DateDiff一起使用:

Now you need to change the script to work with DateDiff:

change perc = 
VAR ValueLastMONTH =
    CALCULATE (
        SUM ( population[TOTAL] ),
        FILTER (
            population,
            DATEDIFF(population[MONTH], EARLIER ( population[MONTH] ),MONTH) = 1
                && population[CATEGORY] = EARLIER ( population[CATEGORY] )

        )
    )
RETURN
    IF (
        ISBLANK ( ValueLastMONTH );
        0; 
        ( population[TOTAL] - ValueLastMONTH )
            / ValueLastMONTH)

这篇关于我想要Power Bi中的脚本,该脚本将计算从一个月到上个月的百分比增加或减少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 09:27