Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

SAMEPERIODLASTYEAR doesn't work with Interval time slicer

Hello,

 

I am using the DAX function "SAMEPERIODLASTYEAR" to compare current units with the same period of the previous year and I want to use a "between" date interval filter.

 

When I include the previous year and this year it works perfectly for the current year data:

 

with 2019.PNG
The problem is that if I select only the year 2020 in the slicer it doesn't return the data for the year 2019 in the "sameperiodlastyear" column:

 

sply.PNG

 

Is there any way for this column to work using this kind of date range filter?

 

Thank you

5 REPLIES 5
Anonymous
Not applicable

Please learn how to correctly use time-intel functions in DAX:

https://www.sqlbi.com/tv/time-intelligence-in-microsoft-power-bi/

Advice: DO NOT EVER USE THE AUTOMATICALLY CREATED DATE HIERARCHY. Create your own. You'll then be safe.

Best
D
nandukrishnavs
Community Champion
Community Champion

@Anonymous 

 

Because you are filtering the dates, so your last year rows will be removed from the context. 

You can use ALL() or ALLEXCEPT() functions to handle this situation. Example https://community.powerbi.com/t5/Desktop/SAMEPERIODLASTYEAR-with-filter/td-p/604118

Refer to this https://www.sqlbi.com/blog/marco/2010/04/05/all-allexcept-and-values-in-dax/

 

Or share your current logic and sample data



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

Anonymous
Not applicable

Hi @nandukrishnavs 

 

My way to calculate the units in the previous period is:

 

units previous period = CALCULATE(SUM('table1'[units]);SAMEPERIODLASTYEAR('Table1'[Datetime].[Date]))

 

I have cheked your links but i still dont understand the way to do it. How i supose to use ALL or ALLEXCEPT in this function?

 

Thank you

@Anonymous 

 

Try this 

units previous period =
CALCULATE (
    SUM ( 'Table1'[units] ),
    ALL ( 'Table1'[Datetime] ),
    SAMEPERIODLASTYEAR ( 'Table1'[Datetime].[Date] )
)

This should work.



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

Anonymous
Not applicable

 

Thank you for your response @nandukrishnavs and @Anonymous  . I have used your formula including the ALL and it does not work perfectly:

 

111.PNG

 

Although the previous day's values are collected well when I filter for the last month of 2017, I need the previous year column (the last one in the capture) and the total to be filtered by the date filtered as well. However, with that formula neither the rows nor the total of the previous period are filtered.

 

Is there any way to solve it?

 

Thank you very much in advance

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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