cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LayneCobain
Frequent Visitor

Latest Price last year

Hi guys,

 

I need some help in a very simplified matter.

 

I have this table:

LayneCobain_0-1660912192395.png

 

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.

 

 

Can anybody please help me?

 

Thank you guys

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @LayneCobain ,

Please try below DAX formula:

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 )

vbinbinyumsft_0-1661240125513.png

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.

View solution in original post

3 REPLIES 3
v-binbinyu-msft
Community Support
Community Support

Hi @LayneCobain ,

Please try below DAX formula:

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 )

vbinbinyumsft_0-1661240125513.png

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.

amitchandak
Super User
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 !!

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.

Helpful resources

Announcements
November 2022 Update

Check it Out!

Click here to read more about the November 2022 updates!

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.