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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
SK16
Frequent Visitor

YTD Year over Year

Hi Guys,

I an facing some issue in Dax.

I want to calculate Year over Year Change for YTD. Like for Feb'20 i have data till feb so I want in YOY change it should select data for 2019 till feb only.

But somehow it is taking taking Full year 2019 data.

 

Can you pls help me out here.

1 ACCEPTED SOLUTION

@SK16 , check the way I suggested to force either Today or max date as a filter in YTD.

You have to force additional date filter on top of YTD

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
Mariusz
Community Champion
Community Champion

Hi @SK16 

 

You can add an If condition to check if the fact table "sales" in my case is empty.

Sales YTD = 
IF( 
    NOT ISEMPTY( Sales ), 
    CALCULATE(
        [Sales],
        DATESYTD( 'Calendar'[Date] )
    )
)
Sales YTD LY = 
CALCULATE(
    [Sales YTD],
    SAMEPERIODLASTYEAR( 'Calendar'[Date] )
)
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

SK16
Frequent Visitor

Hi Mariusz,

 

Thanks for your help buddy.

I got the issue which I am facing in my Dax i.e if I dont select any Month then it is taking Full Previous Year but if  select months from the slicer then it is showing the correct value.

But what I want is that without selecting any month it should consider latest month for YTD.

@SK16 , check the way I suggested to force either Today or max date as a filter in YTD.

You have to force additional date filter on top of YTD

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 Amit,

It really helped

SK16
Frequent Visitor

Hi Mariusz,

 

Thanks for your help buddy.

I got the issue which I am facing in my Dax i.e if if dont select any Month then it is taking Full Previous Year but if I any select months from the slicer then it is showing the correct value.

But I want without selecting any month i should consider lates month for YTD.

 

amitchandak
Super User
Super User

@SK16 

This will work with date calendar.

If you have slicer to pass dates

YTD QTY = TOTALYTD(Sum('order'[Qty]),'Date'[Date])
LYTD QTY = TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year))

 

Using Today

YTD QTY forced=
var _max = today()
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
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)

 

Using Max date

 

YTD QTY forced=
var _max = maxx('order',[Order date])
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced=
var _max1 =maxx('order',[Order date])
var _max = date(year(_max1)-1,month(_max1),day(_max1))
return
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)

 

 

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/

 

 

I am hosting a webinar on 25th April on Power BI, Check Details - https://www.linkedin.com/posts/amitchandak78_webinar-tech-techforgood-activity-6658266754378231808-y...

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 facing same issue for Month to date.

Can you please help me out here.

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.