Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculate the Latest Price

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") is a small subset of my dataset. I need help to calculate the "Benchmark Price" by using a Calculated Column (There are millions of different Item Codes in my dataset and a Measure really slows things down)

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!

  • Try this:

    BP =
    VAR CurrYear = Prices[Year]
    VAR MinYear = CurrYear - 3
    VAR LastZoneYear =
        CALCULATE (
            MAX ( Prices[Year] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Zone] ),
            Prices[Year] > MinYear,
            Prices[Year] < CurrYear
        )
    VAR LastCountryYear =
        CALCULATE (
            MAX ( Prices[Year] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Country] ),
            Prices[Year] > MinYear,
            Prices[Year] < CurrYear
        )
    VAR LastZonePrice =
        CALCULATE (
            MAX ( Prices[Price] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Zone] ),
            Prices[Year] = LastZoneYear
        )
    VAR LastCountryPrice =
        CALCULATE (
            MAX ( Prices[Price] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Country] ),
            Prices[Year] = LastCountryYear
        )
    RETURN
        IF ( ISBLANK ( LastCountryPrice ), LastZonePrice, LastCountryPrice )

2 Replies

  • Try this:

    BP =
    VAR CurrYear = Prices[Year]
    VAR MinYear = CurrYear - 3
    VAR LastZoneYear =
        CALCULATE (
            MAX ( Prices[Year] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Zone] ),
            Prices[Year] > MinYear,
            Prices[Year] < CurrYear
        )
    VAR LastCountryYear =
        CALCULATE (
            MAX ( Prices[Year] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Country] ),
            Prices[Year] > MinYear,
            Prices[Year] < CurrYear
        )
    VAR LastZonePrice =
        CALCULATE (
            MAX ( Prices[Price] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Zone] ),
            Prices[Year] = LastZoneYear
        )
    VAR LastCountryPrice =
        CALCULATE (
            MAX ( Prices[Price] ),
            ALLEXCEPT ( Prices, Prices[Item Code], Prices[Country] ),
            Prices[Year] = LastCountryYear
        )
    RETURN
        IF ( ISBLANK ( LastCountryPrice ), LastZonePrice, LastCountryPrice )
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks a lot Alexis!