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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

PYTD Formula Issues

Hi All,

 

My DAX for PYTD is giving me issues. I have to change the day (e.g. 372 at end of formula) every few months because the number of selling days is different this year from last year. I'd like a permanent solution if possible.

 

PYTD = CALCULATE(SUM('AssaySales'[Extended Sales PMAR Amount]),FILTER(ALL('Date'),AND('Date'[Date]>=01/01/2020,'Date'[Date]<=TODAY()-372)))
 
Is there a way to use the SAMEPERIODLASTYEAR function?
 
Thanks! 
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , you can try measures 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"))

 

 

or like these

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd("Date"[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR("Date"[Date]))

 

 

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

v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

If your dates are contiguous,you could use "DATEADD" or "SAMEPERIODLASTYEAR",otherwise create a date table first.

Then you could use below fomular:

PYTD = CALCULATE(SUM('Table'[Value]),SAMEPERIODLASTYEAR('Table'[Date]))

Or:

PYTD1 = CALCULATE(SUM('Table'[Value]),DATEADD('Table'[Date],-1,YEAR))

And you will see:

vkellymsft_0-1628491233245.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

If your dates are contiguous,you could use "DATEADD" or "SAMEPERIODLASTYEAR",otherwise create a date table first.

Then you could use below fomular:

PYTD = CALCULATE(SUM('Table'[Value]),SAMEPERIODLASTYEAR('Table'[Date]))

Or:

PYTD1 = CALCULATE(SUM('Table'[Value]),DATEADD('Table'[Date],-1,YEAR))

And you will see:

vkellymsft_0-1628491233245.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

amitchandak
Super User
Super User

@Anonymous , you can try measures 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"))

 

 

or like these

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd("Date"[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR("Date"[Date]))

 

 

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
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.

Top Solution Authors