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
DanielM16
Frequent Visitor

SAMEPERIODLASTYEAR returns Blank

I have data that looks like this:

 

Cut-off DateAux_DateCategorySales
23.01.201801.01.2018A1200
24.01.201901.01.2019A8900
25.01.202001.01.2020A6400
23.01.201801.01.2018B1100
24.01.201901.01.2019B5900
25.01.202001.01.2020B2100
23.01.201801.01.2018C4800
24.01.201901.01.2019C2600
25.01.202001.01.2020C1300

 

For a selected Cut-off Date, I want to show the sum of sales for both the selected date and the date one year prior. My issue now is that I can't just use SAMEPERIODLASTYEAR on the Cut-off Date, since the exact day changes from year to year (in 2018, it's the 23rd; in 2019, it's the 24th). I figured I could just add an auxiliary column that contains the first of each month rather than the actual cut-off date (see column Aux_Date). I built two simple measures:

 

Sum_Sales = SUM(Data[Sales])

 

and

 

Sum_Sales_LY = CALCULATE([Sum_Sales], SAMEPERIODLASTYEAR(Data[Aux_Date])).

 

But when I put these on my dashboard, Sum_Sales_LY will show (Blank), if I filter on Cut-off Date:

 

image.png

 

It works fine when I filter on Aux_Date, but that's not what I want:

 

image.png

Is there any way to utilize SAMEPERIODLASTYEAR without having to switch to Aux_Date as filter?

 

Maybe I'm struggling because I can't quite wrap my head around as to why SAMEPERIODLASTYEAR is a valid input for the <filter> argument of the CALCULATE formula. The documentation suggests that SAMERPERIODLASTYEAR returns a single column of data (i.e. the dates incremented by -1 year), and I don't understand how that serves as a filter to anything.

1 ACCEPTED SOLUTION
DanielM16
Frequent Visitor

I actually found the solution myself. Changing the measure to the following does the trick:

Sum_Sales_LY =
var ly = SAMEPERIODLASTYEAR(Data[Aux_Date])
return CALCULATE([Sum_Sales], all(Data[Cut-off Date]), Data[Aux_Date]=ly)

View solution in original post

2 REPLIES 2
DanielM16
Frequent Visitor

I actually found the solution myself. Changing the measure to the following does the trick:

Sum_Sales_LY =
var ly = SAMEPERIODLASTYEAR(Data[Aux_Date])
return CALCULATE([Sum_Sales], all(Data[Cut-off Date]), Data[Aux_Date]=ly)
amitchandak
Super User
Super User

@DanielM16 , Please use the date table in all such cases

 

Year behind Sales = CALCULATE([Sum_Sales],dateadd('Date'[Date],-1,Year))

Year behind Sales = CALCULATE([Sum_Sales],SAMEPERIODLASTYEAR('Date'[Date]))

 

Refer to my video why TI fails: https://www.youtube.com/watch?v=OBf0rjpp5Hw

 

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

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.