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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Msag
Regular Visitor

Bar chart with latest values based on slicer

I am trying to plot in a bar chart the latest price for each product. I would like that bar chart to change as the user changes the latest date through a slicer.

 

Here is my data, the table is called "PriceLog"

 

ProductPriceDate
A37.121/12/2022
B88.921/12/2022
A89.918/12/2022
E50.017/12/2022
B49.015/12/2022
C63.210/12/2022
D5.708/12/2022
A54.905/12/2022
F40.222/11/2022
H31.105/11/2022

 

When the slicer is set with the max date at 21/12/2022, I would like to have this graph plotted

 

Msag_0-1678263748083.png

 21-Dec
A37.1
B88.9
C63.2
D5.7
E50
F40.2
H31.1

 

and when it is set to 15/12/2022

Msag_1-1678263817663.png

 15-Dec
A54
B88.9
C63.2
D5.7
E0
F40.2
H31.1

 

I tried creating a calculated value using DAX:

 

 

lastPrice = 
VAR _tbl = ALLSELECTED(PriceLog)
VAR _maxDate = MAXX(_tbl, PriceLog[Date])
 RETURN CALCULATE(SELECTEDVALUE(PriceLog[Price]), FILTER(_tbl,PriceLog[Date]=_maxDate))

 

 

 

But it did not do the trick.

 

It really feels like I am missing something important in the way I am doing things. Shoud I create another table? If so, how does it update as the user changes the max date through the slicer?

 

Thank you very much for your help!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Msag , Refer if these two can help

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
Msag
Regular Visitor

@amitchandak 

Thank you very much for your answer. Fun fact, I already saw your post on medium! I thought that your solution and what I was doing was similar.... but after trying it, I was apparently completely wrong as yours seems to be working... but I still do not understand the difference between both DAX

 

This is the working solution (yours):

 

latestPrice = 
var _max = maxx(filter(ALLSELECTED(PriceLog), PriceLog[Date] = MAX((PriceLog[Date]))),PriceLog[Date]) 
return 
CALCULATE(max(PriceLog[Price]), filter((PriceLog) ,  PriceLog[Date] = _max))

 

 so "_max"' stores the latest date. This line makes less sense to me as I don't have to handle an ID as you did in your tutorial. Is this line here just to get the latest value from the slicer?

As for the CALCULATE section, I do not understant why "PriceLog[Date] = _max" works.

For example if I take this table again:

ProductPriceDate
A37.121/12/2022
B88.921/12/2022
A89.918/12/2022
E50.017/12/2022
B49.015/12/2022
C63.210/12/2022
D5.708/12/2022
A54.905/12/2022
F40.222/11/2022
H31.105/11/2022

 

If I set the date value to now 09/03/2023, is this going to be the value stored in _max? If so, since I have no product at that date, how is it grabbing the latest value still dated 21/12/2022 ?

 

And if I go back to my original try:

 

lastPrice = 
VAR _tbl = ALLSELECTED(PriceLog)
VAR _maxDate = MAXX(_tbl, PriceLog[Date])
 RETURN CALCULATE(SELECTEDVALUE(PriceLog[Price]), FILTER(_tbl,PriceLog[Date]=_maxDate))

 

 

How is this one any different? When using this one, I also have the ALLSELECTED and the _max. But CALCULATE only returns the price value for the latest date, regardless of the product. So by setting the max date value again at 09/03/2023, it would return the maximum latest value (product B, price = 88.9), and assign this value to all product in the chart, though I don't understand how this one is different to your solution.

 

If you find the time (and motivation) to answer my questions that would be tremandously helpful. In the mean time, thank you so much for all your videos and tutorials, they have already helped me a lot in my journey learning about PBI 🙂 

 

amitchandak
Super User
Super User

@Msag , Refer if these two can help

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors