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

Function 'SAMEPERIODLASTYEAR' expects a contiguous selection Issue

Hello,

 

I have a problem using SAMEPERIODLASTYEAR function to calculate the sales YTD.

 

Here is my setup:

- I have a databable with date called FACT[InvoiceDate]. Format is date.

- I created a calendar table (Date = CALENDAR (DATE(2016,1,1), today())) with date and year column. Format is date.

- The Dates table has a 1-many relationship with the FACT[InvoiceDate] column.

- I am using below formula to measure YTD:

  • Total Sales = SUM(FACT[Sales])
  • Total Sales YTD = TOTALYTD(FACT[Total Sales],DATESYTD('Date'[Date]))
  • Total Sales YTD Last Year = CALCULATE(FACT[Total Sales],SAMEPERIODLASTYEAR('Date'[Date]))

It works if my relationship between date table and FACT table are both ways but I get "Function 'SAMEPERIODLASTYEAR' expects a contiguous selection" if I filter on a specific shop.

Then I changed to single relationship and the result for the previous year is wrong: Total Sales YTD Last Year gives me the total sales for 2017 instead of same period.

 

I went through many post related to this topic but cannot find the solution.

 

Any help is appreciated, thanks in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @v-jiascu-msft,

 

I am using filter instead as follow:

 

TOTAL SALES YTD =
CALCULATE (
    SUM (FACT[Sales] ),
    FILTER (
        ALL ( 'Date' ),
        YEAR ( 'Date'[Date] ) = YEAR ( TODAY () )
            && 'Date'[Date] <= TODAY ()
    )
)

Thanks all for your help!

View solution in original post

17 REPLIES 17

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
Top Kudoed Authors