The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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.
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.
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
@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:
User | Count |
---|---|
16 | |
8 | |
6 | |
6 | |
5 |
User | Count |
---|---|
23 | |
13 | |
13 | |
8 | |
8 |