Power BI: Percent Change Formula

半腔热情 提交于 2019-12-01 12:37:46

问题


I want to create a simple percent change formula in power BI. Specifically, I want to evaluate month over month %change in cost. I know that percent change can be defined in different ways, so to be clear this is the formula that I am referring to:

%change = ([current value] - [previous value])/[previous value].

Here is an example in Excel of what I want to achieve:

I cannot find a way to target a specific row in a DAX formula. It seems that power BI only wants to include aggregate values such as sum, max, etc.

As a final note, I know that PowerBI includes a percent change "quick measure". However, the 'Base Value' always requires you to select aggregate measure instead of a single row value.


回答1:


As Alexis mentioned, there is no concept of referring to a specific row in DAX. It can be a hard notion for people who are used to Excel, but if you want to take advantage of PowerBi, you will have to "unlearn" Excel way of thinking.

To accomplish your goal, you need to do some data modeling first. As a common practice, replace your "Date" column with a proper Calendar table:

Calendar table explained

As a result, you will have a data model in PowerBi that looks something like this:

Once you have such structure in place, DAX is simple:

Current Month Cost = SUM(Expenses[Cost])

Previous Month Cost = CALCULATE( [Current Month Cost], PREVIOUSMONTH(Calendar[Date]))

% Change = DIVIDE( [Current Month Cost] - [Previous Month Cost], [Previous Month Cost])


来源:https://stackoverflow.com/questions/51791874/power-bi-percent-change-formula

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