Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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:
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.
Solved! Go to Solution.
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!
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!