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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

How to calculate multiple year totals based on one selected year

Hi, I want to know how I can calculate sales for past 5 years based on the one year seleted from year filter

RegionSalesYear
A12020
B22020
A12019
B32019
A12018
B42018
A12017
B12017

 

Expected results:

Region2020201920182017
A4321
B10851
1 ACCEPTED SOLUTION

@Anonymous well that is easy

 

TotalSalesPrior1Year = 
VAR __selectedYear = SELECTEDVALUE ( Date[Year] )
VAR __PrevYear = __selectedYear - 1
RETURN Calculate ([TotalSales],Date[Year] = __prevYear)

 

and do -2 for 2 years ago.

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@Anonymous As a best practice, add date dimension in your model and use it for and time intelligence calculations. Once the date dimension is added, mark it as a date table on table tools.

https://perytus.com/2020/05/22/create-a-basic-date-table-in-your-data-model-for-time-intelligence-calculations/

 

And now you can add a measure for cumulative sales and can be shown very easily.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

I have a TotalSales measure which is TotalSales = Sum(Sales[Sales])
I want to have two more measures similar to TotalSales something like

TotalSalesPrior1Year = Calculate (TotalSales,SeletedValue(Date[Year])-1)

TotalSalesPrior2Year = Calculate (TotalSales,SeletedValue(Date[Year])-2)

so when a year is selected in Year filter lets say 2020

then I should be able to display a table like this

RegionTotalSales(CurrentYearSelection)TotalSalesPrior1Year(CurrentYearSelection-1)TotalSalesPrior2Year(CurrentYearSelection-2)
A432
B108 5

@Anonymous well that is easy

 

TotalSalesPrior1Year = 
VAR __selectedYear = SELECTEDVALUE ( Date[Year] )
VAR __PrevYear = __selectedYear - 1
RETURN Calculate ([TotalSales],Date[Year] = __prevYear)

 

and do -2 for 2 years ago.

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Awesome!

That works great

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors