cancel
Showing results for
Did you mean:
Frequent Visitor

## Latest Price last year

Hi guys,

I need some help in a very simplified matter.

I have this table:

All I want is the latest price of the product last year (15.12.2021 - 230 EUR).

I tried this code and got 290 EUR, which is correct, because I didn't tell him to calculate the last year:

``````Last Price =
VAR MaxDate = CALCULATE(MAX('Umsätze Produkt'[Datum]), ALL('Umsätze Produkt'))
RETURN
CALCULATE(SUM('Umsätze Produkt'[Preis]), FILTER('Umsätze Produkt', 'Umsätze Produkt'[Datum] = MaxDate))``````

I found the function "previosyear" but when I tried it, I got a blank result... :S

``````Last Price =
VAR MaxDate = CALCULATE(MAX('Umsätze Produkt'[Datum]), PREVIOUSYEAR('Umsätze Produkt'[Datum]))
RETURN
CALCULATE(SUM('Umsätze Produkt'[Preis]), FILTER('Umsätze Produkt', 'Umsätze Produkt'[Datum] = MaxDate))``````

EDIT: I forgot to mention that in my real model are a lot more different products.

Thank you guys

1 ACCEPTED SOLUTION
Community Support

Hi @LayneCobain ,

``````Measure =
VAR cur_date =
SELECTEDVALUE ( 'Table'[Date] )
VAR cur_year =
YEAR ( cur_date )
VAR tmp =
FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Date] ) = cur_year - 1 )
VAR last_year_latest_date =
CALCULATE ( MAX ( 'Table'[Date] ), tmp )
RETURN
CALCULATE ( MAX ( 'Table'[Price] ), 'Table'[Date] = last_year_latest_date )
``````

Please refer the attached .pbix file

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 REPLIES 3
Community Support

Hi @LayneCobain ,

``````Measure =
VAR cur_date =
SELECTEDVALUE ( 'Table'[Date] )
VAR cur_year =
YEAR ( cur_date )
VAR tmp =
FILTER ( ALL ( 'Table' ), YEAR ( 'Table'[Date] ) = cur_year - 1 )
VAR last_year_latest_date =
CALCULATE ( MAX ( 'Table'[Date] ), tmp )
RETURN
CALCULATE ( MAX ( 'Table'[Price] ), 'Table'[Date] = last_year_latest_date )
``````

Please refer the attached .pbix file

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Super User

@LayneCobain , You should use  a date table for time intelligence

CALCULATE(lastnonblankvalue('Umsätze Produkt'[Datum], SUM('Umsätze Produkt'[Preis])), PREVIOUSYEAR('DAte'[DAte]))

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Learn Power BI P&L Statement || Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s ||
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!
Frequent Visitor

Hello amitchandak,

thank you for you help.

I added a date table and tried your code (test 2). The values are okay but in further calculations the results are "endless". I tried a code (test 1) too but it doesn't work either.

I added some more products and categories so simulate the original data model a little more and uploaded the file here.

The "end-result" should be the difference in percentage between the latest price of the previous year to the highest prices per month in the current year per category (materials).

I really don't know how to do it.