我想要一个 power bi 中的脚本,它将计算从一个月到上个月的百分比增加或减少 [英] I will like a script in power bi that will calculate percentage increase or decrease from one month to the previous month

查看:12
本文介绍了我想要一个 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 中的脚本,它将计算从一个月到上个月的百分比增加或减少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆