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

SAMEPERIODLASTYEAR NOT WORKING

Hi.

I have created a calculated measure using the function SAMEPERIODLASTYEAR but somehow I got the "contiguos date selection" error and I don't know how to fix this.

Thank you for your help.

Daniel Kataoka.




1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

SAMEPERIODLASTYEAR  is a time-intelligent function, so it is recommended to perform this function on a calendar table containing consecutive dates.

Make sure you use  

 CALCULATE([Measure], SAMEPERIODLASTYEAR(Calendar[Date]))

rather than

 CALCULATE([Measure], SAMEPERIODLASTYEAR(Facttable[Date]))

 

You can also try using filter and DATEADD . The dates returned by SAMEPERIODLASTYEAR  are the same as the dates returned by this equivalent formula: DATEADD(dates, -1, year)

 

Other related threads:

Function 'SAMEPERIODLASTYEAR' expects a contiguous selection Issue 

Contiguous date selection error - YTD LY 

sameperiodlastyear only works with contiguous date selection 

 

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
Ed_T
New Member

Adding this solution in case others had the same experience as me.  I was getting the 'Function 'SAMEPERIODLASTYEAR' only works with contiguous date selections' error message on a file that had updated monthly for the past year without issue.  The error appeared after refreshing the data with a dataflow.  During fault finding I tested refreshing the file on a colleague's laptop and it worked fine so I knew I had an issue with my laptop rather than the file itself.

 

The solution on my laptop was a simple clearing of the Excel cache.  As soon as the Excel cache was clear, the file refreshed without the error message coming back and everything worked fine again.

v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

SAMEPERIODLASTYEAR  is a time-intelligent function, so it is recommended to perform this function on a calendar table containing consecutive dates.

Make sure you use  

 CALCULATE([Measure], SAMEPERIODLASTYEAR(Calendar[Date]))

rather than

 CALCULATE([Measure], SAMEPERIODLASTYEAR(Facttable[Date]))

 

You can also try using filter and DATEADD . The dates returned by SAMEPERIODLASTYEAR  are the same as the dates returned by this equivalent formula: DATEADD(dates, -1, year)

 

Other related threads:

Function 'SAMEPERIODLASTYEAR' expects a contiguous selection Issue 

Contiguous date selection error - YTD LY 

sameperiodlastyear only works with contiguous date selection 

 

Best Regards,
Community Support Team _ Eason

amitchandak
Super User
Super User

@Anonymous , You should always use a date table, joined with your table on a date having a single directional join.

 

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-bd52912a5bd4
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 :radacad sqlbi My Video Series Appreciate your Kudos.

 

 

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

Hi, @amitchandak.

Tks for your answer.
I already have a date table joined with my fact/s but I also created another table called SpecialDates where I joined with the column date from the date table.

The SpecialDates table is a table with custom dates: all months (jan, feb, mar, apr..) and anothers custom dates (Last Month, 1 Semester, 2 Semester, YTD, Full Year..)

danielkataoka_0-1660753935636.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.