Reply
MichaelMAU
Frequent Visitor
Partially syndicated - Outbound

SAMEPERIODLASTYEAR Returns values for future date

I am using SAMEPERIODLASTYEAR to create a measure that returns last years sales values. However my Date Table also has future dates for forecasting purposes.

 

My question is how do i prevent the following formula returning values for future periods.

 Here is the formula i have used.

 

PRIOR_PERIOD_SALES =
CALCULATE(
SUM(Sheet1[Sales]),
SAMEPERIODLASTYEAR(DateTable[Date])
)

 

I have then tried various versions of it to filter out future dates to no avail.

 

Here is an example of one formula but still it gives the same result

 

Prior Period Sales = CALCULATE(
SUM(SalesData[Sales]),
SAMEPERIODLASTYEAR(DateTable[Date]),
DateTable[Date] <= EOMONTH(TODAY(), 0),
DateTable[Date] <= TODAY()
)

 

 

Below is a screenshot of the result with the undesired part highlighted in yellow

 

MichaelMAU_0-1744460404328.png

 

 

I would have thought that SAMEPERIODLASTYEAR would have the logic to not repeat this pattern beyond what is current.

 

I would greatly appreciate help with a formula that filters out future dates in this measure. 

 

Thank you

 

 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Syndicated - Outbound

Hi @MichaelMAU -

You're on the right track with using SAMEPERIODLASTYEAR, but the issue is that SAMEPERIODLASTYEAR still returns dates from the prior year, even when you're in a future month (with no current year data yet).

To fix this, we need to ensure that the prior year values are only returned when the current period has actually occurred

 

Prior Period Sales =
VAR CurrentDate = MAX(DateTable[Date])
RETURN
IF (
CurrentDate <= TODAY(), -- Only calculate for dates up to today
CALCULATE(
SUM(SalesData[Sales]),
SAMEPERIODLASTYEAR(DateTable[Date])
)
)

 

can you try this and confirm





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

4 REPLIES 4
rajendraongole1
Super User
Super User

Syndicated - Outbound

Hi @MichaelMAU -

You're on the right track with using SAMEPERIODLASTYEAR, but the issue is that SAMEPERIODLASTYEAR still returns dates from the prior year, even when you're in a future month (with no current year data yet).

To fix this, we need to ensure that the prior year values are only returned when the current period has actually occurred

 

Prior Period Sales =
VAR CurrentDate = MAX(DateTable[Date])
RETURN
IF (
CurrentDate <= TODAY(), -- Only calculate for dates up to today
CALCULATE(
SUM(SalesData[Sales]),
SAMEPERIODLASTYEAR(DateTable[Date])
)
)

 

can you try this and confirm





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Syndicated - Outbound

Hi rajendraongole1,

 

Thank you for assisting with this. This works! Thank you very much. It appears that the Variable is required to define a date range first before moving onto the SAMEPERIODLASTYEAR component of the measure.

MichaelMAU_2-1744500133170.png

 

 

BI_Maverick
New Member

Syndicated - Outbound

Hi @MichaelMAU ,

 

 
Prior Period Sales = CALCULATE( SUM(Sheet1[Sales]), FILTER( SAMEPERIODLASTYEAR(DateTable[Date]), DateTable[Date] <= TODAY() ) )

Could you please try the measure above instead? 


The key is to apply the future date filter directly to the table returned by SAMEPERIODLASTYEAR. This would force the measure to ignore any last‐year dates after today. 

 

Could you please give it a try and confirm if it solved the issue?

 

Regards

Hi BI Maverik 

 

Thanks you trying to help. Unfortunately you measure resulted in future dates having values. This is the issue I have been having with various versions of the formula. For some reason a filter is not being implemented to restrict the dates. 

MichaelMAU_0-1744499714943.png

 

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)