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

Same period from a Specific Year

Hi Guys, 

Need your hand on this, 

 

I have a measure for TY, LY, also 2 Years Ago which is 2019 (When current date selection is on 2021)

Y2 = CALCULATE([Total Sales TY],DATEADD('Date'[Date], -2, YEAR)) This was working perfectly till dec-31- 2021
 
Now when I change current date to 2022, it will pick up a period from Year of 2020 which is two year ago, is there any way to change this measure to pick the date range always from 2019 without creating a new one? The idea is to bring the value from same date range but always the year should be 2019
Need your help on this please.!
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@liboyjoseph , Based on what I got

Try like

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

2nd Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

 

 

or try like

 

LYTD QTY forced=
var _today = maxx(allselected('Order'),'order'[Date]) // or //Today
var _max = date(year(_today)-1,month(_today),day(_today))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

2nd LYTD QTY forced=
var _today = maxx(allselected('Order'),'order'[Date]) // or //Today
var _max = date(year(_today)-2,month(_today),day(_today))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-2,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-2,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-2,year),'Date'[Date]<=_max)

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

View solution in original post

7 REPLIES 7
liboyjoseph
Frequent Visitor

I've tried all this, but no luck. I think my statment was not clear or you did not get my point. Let me explain  

Its similar to sameperiod last year, instad of last year, I need 2019. 

@liboyjoseph , Then you can fix it like

2019 Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(all('Date'[year]),'Date'[year] =2019))

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

 

Thanks @amitchandak  but it doesn't work for me. 

liboyjoseph_0-1641321688019.png

 

 

@liboyjoseph , Please create Year a column in date table. Do not use.Year . TI does not work well with that

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...

You can also try

Y3 =

var _diff = 2019 - maxx(allselected('Date'), 'Date'[Year]) )

//or var _diff = 2019 - year(maxx(allselected('Date'), 'Date'[date]) ))

return

CALCULATE([Total Sales TY],DATEADD('Date'[Date], _diff , YEAR))

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

Hi @liboyjoseph 

Have you solved this question with amitchandak's help? If you have solved the question, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.

If you need more help, please let me know.

 

Best Regards,

Community Support Team _Tang

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

liboyjoseph
Frequent Visitor

Thank you so much @amitchandak , Let me try this and will get back to you
amitchandak
Super User
Super User

@liboyjoseph , Based on what I got

Try like

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

2nd Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

 

 

or try like

 

LYTD QTY forced=
var _today = maxx(allselected('Order'),'order'[Date]) // or //Today
var _max = date(year(_today)-1,month(_today),day(_today))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

2nd LYTD QTY forced=
var _today = maxx(allselected('Order'),'order'[Date]) // or //Today
var _max = date(year(_today)-2,month(_today),day(_today))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-2,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-2,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-2,year),'Date'[Date]<=_max)

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

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.