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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Laughter
New Member

Sameperiodlastyear() doesnot return the calculation for the last year but the last two years

Dear community:

 

I calculate the unit price using power bi sameperiodlastyear() , I have a small database it contains only sales of 2022 till today which is feb 2024. and I want to know yoy% , the returned calculation is not correct, I found out the reason is, sameperiodlastyear() take 2022 and 2023 two years sale data to calculate unit price instead of using only 2023 year's data , why?

 

this is my code for yoy% in calculation group

 

this is my YoY% measure using calculation group:DIVIDE( CALCULATE( SELECTEDMEASURE(), FILTER( DateTable, INT( 'DateTable'[Year] ) = YEAR( MAX('T sales'[invoice date]) ) ) ), CALCULATE( SELECTEDMEASURE( ), SAMEPERIODLASTYEAR(DateTable[date]) ) )-1

 

when i using this measure, it compares the unit price of 2024 with 2022 and 2023 data together, ( this means it uses total sales of 2022+2023 divide total quantity of 2022+2023, which is incorrect. 

 

I think I don't understand the behaviour of sameperiodelastyear() quite well.

3 REPLIES 3
Anonymous
Not applicable

Hi @Laughter ,

 

According to your statement, I think your issue may be that your measure in calculation group will return the data in two years instead of one year.

As far as I know, the result it result is based on the measure you use in SELECTEDMEASURE().

So we need more information about your measure.

Please share a sample file with us and show us a screenshot.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

latimeria
Solution Specialist
Solution Specialist

Hi @Laughter ,

You need to reference a measure with the first period

VAR Period1 = 
  CALCULATE( 
    SELECTEDMEASURE(), 
    FILTER( DateTable, year( 'DateTable'[date] ) = YEAR( MAX('T sales'[invoice date]) ) ) 
)
VAR Period2 = 
  CALCULATE( 
    Period1, 
    SAMEPERIODLASTYEAR(DateTable[date]) 
)
RETURN
  DIVIDE( Period1, Period2) -1

 You can write periodd2 as this, if you prefer

VAR Period2 = 
  CALCULATE( 
    Period1, 
    dateadd(DateTable[date],-1,year) 
)

 

You can find usefull information here: Differences between DATEADD and PARALLELPERIOD in DAX - SQLBI

 

Greg_Deckler
Community Champion
Community Champion

@Laughter You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

Also:



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.