Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
jonbrooker
Helper I
Helper I

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!

1 ACCEPTED SOLUTION
ThxAlot
Super User
Super User

ThxAlot_0-1716522970627.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

3 REPLIES 3
jonbrooker
Helper I
Helper I

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!

ThxAlot
Super User
Super User

ThxAlot_0-1716522970627.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Kaviraj11
Solution Specialist
Solution Specialist

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)
 
 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.