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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Lora_0121
Helper I
Helper I

How to Calculate Previous Year Sales with Date Filters Applied

Hello.

I have slicers for Year, Quarter, and Team, and I am trying to calculate a metric that is affected by these filters.

1.  When all dates are selected, py_sales is displayed in table1, but not in table2.
sales1.png

 

2. When only one year is selected, py_sales is not displayed in either table1 or table2.

 244c5084-5925-4bcd-ae68-80a62bcd4eb2.png

 

How can I calculate previous year sales for the selected period in the slicer?
Here is the py_sales formula I wrote:

PY_sales = 
CALCULATE(
    SUM(Sheet1[sales]), 
    SAMEPERIODLASTYEAR('Sheet1'[Date])
)

 



Thank you.

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Lora_0121 

 

A dedicated Dates dimension table with a full range of dates and columns for year, quarter, and month would simplify your time intelligence calculations. You can create such a table using DAX or M, relate its Date column to your fact table in a one-to-many relationship and ensure that the Dates table have been marked as such.

 

danextian_0-1741602069141.png

danextian_1-1741602286482.png

 

Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

7 REPLIES 7
v-sathmakuri
Community Support
Community Support

Hi @Lora_0121 ,

 

I hope this information proves helpful. Feel free to reach out if you have any further questions or would like to discuss this in more detail. If responses provided answers your question, please accept it as a solution so other community members with similar problems can find a solution faster.

 

Thank you.

v-sathmakuri
Community Support
Community Support

Hi @Lora_0121 ,

 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

 

Thank you!!

v-sathmakuri
Community Support
Community Support

Hi @Lora_0121 ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

danextian
Super User
Super User

Hi @Lora_0121 

 

A dedicated Dates dimension table with a full range of dates and columns for year, quarter, and month would simplify your time intelligence calculations. You can create such a table using DAX or M, relate its Date column to your fact table in a one-to-many relationship and ensure that the Dates table have been marked as such.

 

danextian_0-1741602069141.png

danextian_1-1741602286482.png

 

Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
ryan_mayu
Super User
Super User

@Lora_0121 

if you want to use time intelligence functions, you need to have a date table

 

https://learn.microsoft.com/en-us/dax/dateadd-function-dax?wt.mc_id=DP-MVP-5004616

https://learn.microsoft.com/en-us/dax/sameperiodlastyear-function-dax?wt.mc_id=DP-MVP-5004616

 





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

Proud to be a Super User!




'Sheet1'[Date] is in date format.
sales3.png

 

I know you have a date column in your main table.

You need to have a new date table and build relationship between two tables

 

11.PNG

pls see the attachment 





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

Proud to be a Super User!




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.