Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.