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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 38 | |
| 36 | |
| 33 | |
| 32 | |
| 28 |
| User | Count |
|---|---|
| 129 | |
| 88 | |
| 79 | |
| 68 | |
| 63 |