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

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