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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
vwiles84
Helper III
Helper III

Prior Year Sales - Filter (Retail comparison)

I have established a connection to a table in SQL that has all of the data I need in my report.  I want to calculate Prior year sales based on a single date filter.  I need the prior year to be the exact day of the week as last year not necessarily the same date.  For example last year from today's date (Tuesday 2/11/2020) is Tuesday 2/12/2019.  In my table, there is daily sales data starting from 2014 up to current.  I have created another date calendar table in Power BI that does a calculation to determine what the last year's date is.  What I cannot get it how to write the calculation to pull in the sum of sales based on the DayLY column in this calendar table. Any ideas?

1 ACCEPTED SOLUTION
v-diye-msft
Community Support
Community Support

Hi @vwiles84 

 

Sorry for my late reply. I can't check your sample pbix anymore coz it's expired. 

I created a sample below to calculate the prior date by conditions for your reference:

Measure = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[year]=YEAR(MAX('Table'[Date]))-1&&[weeknum]=WEEKNUM(MAX('Table'[Date]))&&[weekday]=WEEKDAY(MAX('Table'[Date]),2)))

04.PNG 

and you can calculate the sales by filter the date=[measure].

Pbix attached.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

View solution in original post

5 REPLIES 5
v-diye-msft
Community Support
Community Support

Hi @vwiles84 

 

Sorry for my late reply. I can't check your sample pbix anymore coz it's expired. 

I created a sample below to calculate the prior date by conditions for your reference:

Measure = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[year]=YEAR(MAX('Table'[Date]))-1&&[weeknum]=WEEKNUM(MAX('Table'[Date]))&&[weekday]=WEEKDAY(MAX('Table'[Date]),2)))

04.PNG 

and you can calculate the sales by filter the date=[measure].

Pbix attached.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
v-diye-msft
Community Support
Community Support

Hi @vwiles84 

 

you might consider creating pbix file that will contain some sample data (remove the confidential info), upload the pbix to onedrive or dropbox and share the link to the file. Please do not forget to describe the expected results based on this sample data.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

OK, I have created a PBIX file with the data in question. I am trying to make the prior year sales measure equal the sales from last year (NOT SAME DAY LAST YEAR, but same day of the week regardless of date). 

Sample PBIX File 

amitchandak
Super User
Super User

Last year the same weekday is 364 days behind. So as long as you view a Day or view by week this formula should work.

Week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,DAY))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

When i add that command, it is pulling the exact same number as this year sales. It's not bringing up last year.

 

What do you mean when you said this: Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.? 

 I have the date table and it has a one to many relationship to my sales data table. 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.