Xiaowan Wen
Xiaowan Wen

Reputation: 145

Power BI how to display latest value of a column based on date slicer and filter?

I have a Power BI table looks like this:

Cat Price Date
apple 2.0 03/21/2021
peach 3.0 03/22/2021
apple 1.8 03/18/2021
apple 2.0 03/19/2021
peach 3.1 03/20/2021
apple 1.7 03/17/2021

I want to use a date slicer and Cat filter to choose the latest price for Apple and display in a tile:

Date Slicer: 03/12/2021 - 03/21/2021
Filter: check 'apple'

Tile display: 2.0

I tried

price_LastValue := CALCULATE(SUM(fruit[Price]), LASTDATE(fruit[Date]))

but the result is BLANK. Any thoughts?

Upvotes: 2

Views: 12589

Answers (1)

ZygD
ZygD

Reputation: 24478

price_LastValue = 
VAR _tbl = ALLSELECTED(Table1)
VAR _max_date = MAXX(_tbl, [Date])
RETURN MINX(FILTER(_tbl, [Date] = _max_date), [Price])

enter image description here

Upvotes: 2

Related Questions