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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
kg4u
Helper II
Helper II

YTD LY Calculation not working

Hi,

 

I cannot figure out why my YTD LY calculation is not working.  Can someone take a look and help me?  I would expect to see the same value in August - December for the YTD Sale LY calculation but it is continuing to add values it should stop adding values in July.  I want to compare the same period this year compare to the same period last year.

 

kg4u_0-1689947377532.png

Here are my calculations. 

Total Sales = SUM(Data[Original Sales])
YTD Sales = TOTALYTD([Total Sales],'CALENDAR'[Date].[Date])
YTD Sales LY = TOTALYTD(SUM(Data[Original Sales]), DATEADD('CALENDAR'[Date],-1,year))
 
What am I doing wrong? Or is there a better YTD LY calculation I should use? 
Thank you so much!

 

2 REPLIES 2
amitchandak
Super User
Super User

@kg4u , You have control that

examples

 

LYTD QTY forced=
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)

 

 


LYTD QTY forced=
var _today = maxx(allselected('Order'),'order'[Date])
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)

 

comments // are an alternate formula for return

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

I am trying to use your examples, which I am very thankful for.  However, they are giving me an error.

Seems that I am not using MAX correctly, please advise. 

 

kg4u_0-1689950619756.png

 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.