Forum Discussion

jonbrooker's avatar
jonbrooker
Helper I
2 years ago
Solved

Calculating difference from previous year by area

Hi, I wonder if anyone can help me with what I was hoping would be a relatively common calculation, but I've so far failed to find a solution.

I need to calculate the difference in [Value] from the previous year, with the calculation resetting with the area name. An example of the data structure is shown below. I am trying to get PowerBI to calculate the 'Difference from previous year' column to get the values shown.

 

AreaYearValueDifference from previous year
Area 120155001 
Area 1201662001199
Area 120174980-1220
Area 120182634-2346
Area 1201952842650
Area 120206114830
Area 1202172131099
Area 120226003-1210
Area 220151984 
Area 220162103119
Area 22017211512
Area 220182301186
Area 220192286-15
Area 220202199-87
Area 220212311112
Area 22022238574
Area 320157150 
Area 32016718535
Area 32017723348
Area 320187345112
Area 320197534189
Area 320207684150
Area 32021769915
Area 32022774243

Any help gratefully received!

3 Replies

  • Hi,

     

    To work with time intelligence function, we must have a date/calendar table. Make sure to have it created and relationship is created. Additionally, use the Year column(hierarchy) from the  Date column of Date/Calendar Table

     

    Next, you create a previous year value/data as:

     

    Previous Year  =
    VAR PREVIOUS=CALCULATE(SUM(Table[Value]),PREVIOUSYEAR('Calendar'[Date].[Date]))
    RETURN IF(ISBLANK(PREVIOUS),0,PREVIOUS)
     
    Second Measure:
    Difference = SWITCH(TRUE(),[Previous Year]=0,BLANK(),CALCULATE(SUM(Table[Value])-[Previous Year)
     
     
  • Thank you both so much for replying.

     

    I couldn't get the solution by Kaviraj11 to work (presumably my fault), but the code supplied by ThxAlot worked a treat and I've been able to apply it to my real-life data. Excellent stuff!