Search code examples
powerbidaxdata-analysispowerbi-desktopmeasure

Power BI: Finding earliest price per category


I have a table in PBI where I have three columns: Category, Price, and Date.

I want to create a measurement that shows the earliest price per category, no matter what filters are set on the Date column.

For example, my table looks like this:

Category Price Date
A 10 2022-01-01
A 15 2022-02-01
A 12 2022-03-01
B 20 2022-01-01
B 15 2022-02-01
B 12 2022-03-01

And when I add my measurement to the table, it should look like:

Category Price Date Earliest Price
A 10 2022-01-01 10
A 15 2022-02-01 10
A 12 2022-03-01 10
B 20 2022-01-01 20
B 15 2022-02-01 20
B 12 2022-03-01 20

I have tried using this measurement, but can't get it to work:

Earliest price = 
CALCULATE(
   SUM('Table'[Price]),
   'Table'[Date] = MIN('Table'[Date]),
   ALL('Table'[Date])
)

Thanks in advance!


Solution

  • Earliest = 
    VAR x = CALCULATE(MIN('Table'[Date]), ALLEXCEPT('Table', 'Table'[Category]))
    RETURN 
    CALCULATE(MIN('Table'[Price]),  ALLEXCEPT('Table', 'Table'[Category]), 'Table'[Date] = x)
    

    OR

    Earliest = 
    CALCULATE(
        FIRSTNONBLANKVALUE('Table'[Date], MAX('Table'[Price])), 
        ALLEXCEPT('Table','Table'[Category])
        )