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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jeggen
Helper I
Helper I

Calculating Year over Year by ID

I am looking for a way to calculate year-over-year trends for different categories but am not sure how to get started on this.

 

Here is an example of how this data works: (note: Sales1 and units are separate columns)

IDYearSales1    Units    
12320185000052
45620183500034
78920182500031
15920182200029
26720183700035
48120185100053
12320195200054
45620193700035
78920192400030
15920192100028
26720193300030
48120195500056
12320203500028
45620203900037
78920202500031
15920202300030
26720202900028
48120205700058

In this example I would like to be able to, as an example, calculate a multi-year growth/decline for each individual based on "ID." I would be okay with a % growht/decline for this year to last and/or something that would indicate two years of consecutive growth/delcine.

 

IF these were all on one line per ID I'd have a sense of what to do with a formulate. Since there is one line per ID/Year that's where I get stuck. This is the only way I can really get this data out of our system unless I pull in one data set per year.

 

Any suggestions on how I can calculate year-over-year with this kind of data?

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@jeggen 

you can try to create a column

Column = 
VAR _last=maxx(FILTER('Table','Table'[ID]=EARLIER('Table'[ID])&&'Table'[Year]=EARLIER('Table'[Year])-1),'Table'[Sales1    ])
RETURN IF(ISBLANK(_last),BLANK(),'Table'[Sales1    ]/_last-1)

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
jeggen
Helper I
Helper I

This is fantastic, thank you. Works great and provides YoY for any year that has a previous year's value available!

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

@jeggen 

you can try to create a column

Column = 
VAR _last=maxx(FILTER('Table','Table'[ID]=EARLIER('Table'[ID])&&'Table'[Year]=EARLIER('Table'[Year])-1),'Table'[Sales1    ])
RETURN IF(ISBLANK(_last),BLANK(),'Table'[Sales1    ]/_last-1)

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@jeggen , Create a seperate year table(Say Date)  with distinct year then create measures like

 

This Year = CALCULATE(sum('Table'[Sales1]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Sales1]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

diff = [This Year]-[Last Year]
diff % = divide([This Year]-[Last Year ],[Last Year])

Would the table actually need to be one row per distinct ID? I'm trying to calculate Year over Year values for each unique ID.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.