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
Anonymous
Not applicable

Calculate the Latest Price from within previous 3 years for all items

Row No.ZoneItem CodeCountryYearPriceBenchmark Price (BP)
1West EURABelgium2015 --
2West EURABelgium2016102-
3West EURABelgium2017104102
4West EURABelgium2018106104
5West EURABelgium2020110106
6West EURANetherlands2019120106
7West EURANetherlands2020122120
8West EURANetherlands2020124120
9West EURANetherlands2021124124

 

Above table (from column "Row No." to column "Price") represents my dataset. I need help to calculate the "Benchmark Price". 

This is the logic for Benchmark Price (BP) -
BP is the "Latest Price within the last 3 years. This should be preferably from the same country but if not then at least from the same zone." If a purchase has been made within the last 3 years in the same country, then that price will be the BP. If a purchase has not been made within the last 3 years in the same country, then see if it has been purchased in at least the same zone. If yes, then that price will be BP (even though it might be from another country).

Explaining with examples-

Row No. 2 - There is no BP as item was not purchased in 2015 in Belgium and data before 2015 is not available. Item not purchased in 2015 in Netherlands (same zone) as well. 
Row No. 6 - The item was not purchased in Netherlands before 2019. However, we have a purchase made in the same Zone i.e. in Belgium. So BP will be the 2018 Belgium Price. (If 2018 Belgium Price wasn't available, then 2017 Belgium Price would have been the BP. If 2017 Belgium Price was also not available then 2016 Belgium Price would have been the BP. Only if none of 2018, 2017, 2016 prices were available in the entire Zone, then there would have been no BP. Even if 2015 Prices were available they would not have worked as they would be beyond the 3 year time frame.)

Row No. 9 - We have 2 prices for 2020 in the same country i.e. Netherlands. In such cases choose the higher price. 124 > 122 so BP is 124.

I have also done some color-coding to make it easier to understand where the BP is coming from.
Please let me know if there are any questions.
Would appreciate all help. Thanks in advance!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

BP measure : =
VAR currentcountry =
MAX ( Data[Country] )
VAR currentzone =
MAX ( Data[Zone] )
VAR currentyear =
MAX ( Data[Year] )
VAR samecountry_previousthreeyears =
FILTER (
ALL ( Data ),
Data[Country] = currentcountry
&& Data[Year] < currentyear
&& Data[Year] >= currentyear - 3
&& NOT ( ISBLANK ( Data[Price] ) )
)
VAR samecountry_maxofpreviousyears =
MAXX ( samecountry_previousthreeyears, Data[Year] )
VAR samezone_previousthreeyears =
FILTER (
ALL ( Data ),
Data[Zone] = currentzone
&& Data[Year] < currentyear
&& Data[Year] >= currentyear - 3
&& NOT ( ISBLANK ( Data[Price] ) )
)
VAR samezone_maxofpreviousyears =
MAXX ( samezone_previousthreeyears, Data[Year] )
VAR samecountry_BP =
GROUPBY (
FILTER (
samecountry_previousthreeyears,
Data[Year] = samecountry_maxofpreviousyears
),
"@BP", MAXX ( CURRENTGROUP (), Data[Price] )
)
VAR samezone_BP =
GROUPBY (
FILTER ( samezone_previousthreeyears, Data[Year] = samezone_maxofpreviousyears ),
"@BP", MAXX ( CURRENTGROUP (), Data[Price] )
)
RETURN
COALESCE (
IF (
HASONEVALUE ( Data[Row No.] ),
SWITCH (
TRUE (),
NOT ( ISBLANK ( samecountry_BP ) ), samecountry_BP,
NOT ( ISBLANK ( samezone_BP ) ), samezone_BP
)
),
" "
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

BP measure : =
VAR currentcountry =
MAX ( Data[Country] )
VAR currentzone =
MAX ( Data[Zone] )
VAR currentyear =
MAX ( Data[Year] )
VAR samecountry_previousthreeyears =
FILTER (
ALL ( Data ),
Data[Country] = currentcountry
&& Data[Year] < currentyear
&& Data[Year] >= currentyear - 3
&& NOT ( ISBLANK ( Data[Price] ) )
)
VAR samecountry_maxofpreviousyears =
MAXX ( samecountry_previousthreeyears, Data[Year] )
VAR samezone_previousthreeyears =
FILTER (
ALL ( Data ),
Data[Zone] = currentzone
&& Data[Year] < currentyear
&& Data[Year] >= currentyear - 3
&& NOT ( ISBLANK ( Data[Price] ) )
)
VAR samezone_maxofpreviousyears =
MAXX ( samezone_previousthreeyears, Data[Year] )
VAR samecountry_BP =
GROUPBY (
FILTER (
samecountry_previousthreeyears,
Data[Year] = samecountry_maxofpreviousyears
),
"@BP", MAXX ( CURRENTGROUP (), Data[Price] )
)
VAR samezone_BP =
GROUPBY (
FILTER ( samezone_previousthreeyears, Data[Year] = samezone_maxofpreviousyears ),
"@BP", MAXX ( CURRENTGROUP (), Data[Price] )
)
RETURN
COALESCE (
IF (
HASONEVALUE ( Data[Row No.] ),
SWITCH (
TRUE (),
NOT ( ISBLANK ( samecountry_BP ) ), samecountry_BP,
NOT ( ISBLANK ( samezone_BP ) ), samezone_BP
)
),
" "
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Thanks a lot for providing the solution 🙂 ! Quick follow up. I need to add 2 more columns:
1. BP Year (This tells us from which year the BP was taken)
2. BP Country (This tell us from which country the BP was taken)

For example in above data set for Row No. 6 -
BP = 106
BP Year = 2018
BP Country = Belgium 

Appreciate your help ! Thanks again ! 

Anonymous
Not applicable

@amitchandakrequesting assistance sir !

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.

Users online (2,456)