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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
zolotrip
Regular Visitor

Maximum value in dynamic date range

Hi there.

 

It might sound simple, but I have been looking this solution up for quite a long time, almost everywhere on the internet, unsuccesfully, so far.

 

I would need something "dynamic", let's say, in the sense that I need to have the max value in the last 3 days, in the context of every row. Just like this:

 

zolotrip_0-1640937133813.png


calculate(max(Table[value]), filter(all(Table), Table[date] >= max(Table[date]) -3))

Or

calculate(max(Table[value]), filter(all(Table), Table[value] = max(Table[value]) && Table[date] >= max(Table[date]) -3))

 

None of the two solutions shown above are working for me.

The first one is giving "25" for every row. The second one is giving blank for every row.

I am writting the DAX formulas on Power Pivot, but I guess that's not the reason.

 

Any ideas?

 

Many thanks to everyone.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@zolotrip , Please find code for new column and measure

 

new column =
maxx(filter(Table, Table[date] >= earlier(Table[Date]) -3 && Table[date] <= earlier(Table[date])),[Table[value])

 


new measure =
maxx(filter(allselected(Table), Table[date] >= max(Table[Date]) -3 && Table[date] <= max(Table[date])),[Table[value])

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

5 REPLIES 5
ValtteriN
Super User
Super User

Hi,

This pattern ought to do what you want:

MaxLast3 =
var Cdate =SELECTEDVALUE('calendar'[Date])-3 return
CALCULATE(MAX(MaxLast[Value]),ALL('MaxLast'[Date]),DATESBETWEEN('calendar'[Date],Cdate,Cdate+3))

Test data:
ValtteriN_0-1640939364417.png


End result:

ValtteriN_1-1640939389115.png

 

I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Dear @ValtteriN :

 

I don't have available the SELECTEDVAUE expression in Power Pivot, I'm afraid.

Do you know an equivalent to it?

 

Thank you so much.

Hi,

You can either use MAX it often works in a similar way or this pattern: IF(HASONEVALUE([column]), VALUES([column]), [alternateresult]).





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@zolotrip , Please find code for new column and measure

 

new column =
maxx(filter(Table, Table[date] >= earlier(Table[Date]) -3 && Table[date] <= earlier(Table[date])),[Table[value])

 


new measure =
maxx(filter(allselected(Table), Table[date] >= max(Table[Date]) -3 && Table[date] <= max(Table[date])),[Table[value])

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

Dear  @amitchandak:

 

Thank you for your quick response. It's working perfectly.

 

Best regards.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.