I want to calculate the monthly change of this serie which is already on a monthly basis. So my question is how I could calculate the change for each row (starting from the second row).
CodePudding user response:
You just need to create this one measure:
% Change =
VAR thisDate = MAX('Table'[Datum])
VAR previousDate =
CALCULATE(
MAX('Table'[Datum]),
'Table'[Datum] < thisDate
)
VAR thisPrice = MAX('Table'[Omifx])
VAR previousPrice =
CALCULATE(
MAX('Table'[Omifx]),
'Table'[Datum] = previousDate
)
RETURN
IF(
NOT ISBLANK(previousPrice),
DIVIDE(
thisPrice - previousPrice,
previousPrice
)
)
CodePudding user response:
the proper way of doing it is as follows:
- Create the following DAX Table:
Calendar_Table =
var startyear = year(min(datatable[Datum]))
var endyear = year(max(datatable[Datum]))
var result =
ADDCOLUMNS(
CALENDAR(DATE(startyear, 1, 1), DATE(endyear, 12, 31)),
"Calendar Year", YEAR([Date]),
"Month Name Short", FORMAT( [Date], "mmm" ),
"Month Order", FORMAT( [Date], "mm" )
)
return result
- create a data model by linking [Date] column in calendar_table with [Datum] column
- create the following DAX Measure
Previous Day Total =
CALCULATE(
sum(datetable[Omifx]),
DATEADD('Date Table'[Date], -1, DAY)
)
- create a new DAX Measure
Change = sum(datatable[Omifx]) - [Previous Day Total]
there is more in the blog post: https://medium.com/analytics-vidhya/almost-everything-you-need-to-know-about-dates-in-power-bi-2f24c64c5671