percentage difference with month and year and count in table using DAX

泪湿孤枕 提交于 2019-12-06 10:51:07

问题


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   

回答1:


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




回答2:


How about using below code:

SUM(Sheet1[records]) /CALCULATE(SUM('Sheet1'[records]), ALL('Sheet1'[Month]))


来源:https://stackoverflow.com/questions/52598381/percentage-difference-with-month-and-year-and-count-in-table-using-dax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!