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
GretchenRW
Frequent Visitor

Dynamically calculate previous year based on slicer

I'm trying to create a matrix visual that dynamically changes the current year calculations based on the year selected in a slicer. My data set contains data from 2023-2025 and I need to calculate YTD Sales, YTD Qty, Prior YTD Sales and Prior YTD Qty with the current YTD changing along with the date selected within the slicer. I've been able to calculate YTD for this year and create a -1 calculation to determine the prior year, but that is only working if 2025 is selected. I know there is a way to do this, I just can't find the right tutorial. Any help you can provide would be greatly appreciated.

2 ACCEPTED SOLUTIONS

SAMEPERIODLASTYEAR is notoriously bad with custom fiscal calendars.  Better use an external reference table that has the required columns precomputed.

View solution in original post

Anonymous
Not applicable

Hi, @GretchenRW 

Avoid using time intelligence functions on non-standard dates:

SAMEPERIODLASTYEAR – DAX Guide

vjianpengmsft_0-1739173012904.png

You should install the example from the entire blog below, by doing the PY,YOY calculations without relying on the temporal intelligence function.

Week-related calculations – DAX Patterns

 

vjianpengmsft_1-1739173352205.png

For standard time, you can use the Time Intelligence function as instructed in the blog below.

Standard time-related calculations – DAX Patterns

vjianpengmsft_2-1739173581860.png

If your date table is more customizable, you can also customize the time calculation YOY:

Custom Year-Over-Year Calculation in DAX - SQLBI

vjianpengmsft_3-1739173786700.png

Computing MTD, QTD, YTD in Power BI for the current period - SQLBI

 

 

Best Regards

Jianpeng Li

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
Anonymous
Not applicable

Thank you lbendlin 

Hi, @GretchenRW 

You can learn how to calculate dynamic YTD in this tutorial below:

Week-related calculations – DAX Patterns

OR watch video:
How to Build Dynamic MTD YTD DAX calculations in Power Bi | Time intelligence functions | DAX - YouT...

vjianpengmsft_0-1738826237079.png

You can also refer to the article on PYTD for practice:

vjianpengmsft_1-1738826732334.png

I've uploaded a sample PBIX file below:

vjianpengmsft_2-1738826979118.png

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

lbendlin
Super User
Super User

There's a lot of ways to do this.  Can you confirm that your data model has a Calendar table?  Have you considered using Visual Calculations?

I have a fiscal calendar that breaks each day into the appropriate fiscal period. So far I have tried utilizing SAMEPERIODLASTYEAR but it is not returning the expected results.

Anonymous
Not applicable

Hi, @GretchenRW 

Avoid using time intelligence functions on non-standard dates:

SAMEPERIODLASTYEAR – DAX Guide

vjianpengmsft_0-1739173012904.png

You should install the example from the entire blog below, by doing the PY,YOY calculations without relying on the temporal intelligence function.

Week-related calculations – DAX Patterns

 

vjianpengmsft_1-1739173352205.png

For standard time, you can use the Time Intelligence function as instructed in the blog below.

Standard time-related calculations – DAX Patterns

vjianpengmsft_2-1739173581860.png

If your date table is more customizable, you can also customize the time calculation YOY:

Custom Year-Over-Year Calculation in DAX - SQLBI

vjianpengmsft_3-1739173786700.png

Computing MTD, QTD, YTD in Power BI for the current period - SQLBI

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

SAMEPERIODLASTYEAR is notoriously bad with custom fiscal calendars.  Better use an external reference table that has the required columns precomputed.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 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