Home > OS >  How can I calculate the percentage change of a serie in DAX Power BI?
How can I calculate the percentage change of a serie in DAX Power BI?

Time:12-09

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).

enter image description here

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
        )
    )

enter image description here

CodePudding user response:

the proper way of doing it is as follows:

  1. 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
  1. create a data model by linking [Date] column in calendar_table with [Datum] column
  2. create the following DAX Measure
Previous Day Total = 
  CALCULATE( 
    sum(datetable[Omifx]), 
    DATEADD('Date Table'[Date], -1, DAY) 
  )

  1. 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

  • Related