与月份和年份的百分比差异以及使用DAX的表格中的计数 [英] percentage difference with month and year and count in table using DAX

查看:145
本文介绍了与月份和年份的百分比差异以及使用DAX的表格中的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用DAX函数获得月份和年份的百分比差异

I am trying to get percentage difference with month and year using DAX function

Month   Year          records
Jan      2015          100
Feb      2015          120
Mar      2015          140
Apr      2015          160 

并且我正在尝试在新列中计算差异百分比

and I am trying to calculate percentage diff in a new column

Month    Year          records   %change
Jan      2015          100        0%
Feb      2015          120        20%
Mar      2015          140        17.02%
Apr      2015          180        22%.03   


推荐答案

在您当前的设置中,这样的操作可能有效。使用日期表会更好,也更容易。

In your current setup, something like this could work. Using a datetable would be better and easier though.

%change = 
VAR StartLastMonth =
    ( DATE ( 'table'[Year], 'table'[Month] - 1, 1 ) )
VAR RecordsLastMonth =
    CALCULATE (
        MAX ( 'table'[Records] ),
        FILTER (
            'table',
            'table'[Year] = YEAR ( StartLastMonth )
                && 'table'[Month] = MONTH ( StartLastMonth )
        )
    )
RETURN
    IF (
        ISBLANK ( RecordsLastMonth ),
        BLANK (),
        'table'[Records] - RecordsLastMonth
    )
        / RecordsLastMonth

这篇关于与月份和年份的百分比差异以及使用DAX的表格中的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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