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
toum
Helper II
Helper II

Max date

Please I need your help on this,

I need to create a measure to calculate the max date of a table that is between two other dates (Date Slicer)

so for example, if in my slicer I chose a date between 2021/1/20 and 2021/2/18, and my table has these dates 

toum_0-1673970519801.png

We should take 30/1/2021 that's the max date in the table when the date is between  2021/1/20 and 2021/2/18

 

 

1 ACCEPTED SOLUTION

Hi , @toum 

According to your description, you want to create a date slicer and you need to get the max date in table in the selected date range you selected.

Here are teh steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1674009597344.png

(2)We can click "New Table" to  create a date table as a slicer:

Date SLicer = CALENDAR(FIRSTDATE('Table'[Date]) , LASTDATE('Table'[Date]))

(3)Then we can create a measure :

Max Date = var _min_date = MIN('Date SLicer'[Date])
var _max_date = MAX('Date SLicer'[Date])
var _t = FILTER(ALLSELECTED('Table') ,'Table'[Date]>=_min_date && 'Table'[Date]<= _max_date)
return
MAXX(_t ,[Date])

(4)Then we can put the filed we need on the visual and then we can meet your need the result is as follows:

vyueyunzhmsft_1-1674009658073.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table.  Create a relationship (Many to One and Single) from the Date column of the Data Table to the Date column of the Calendar Table.  Write these measures

Total = sum(Data[Sale])

Farthest date = MAXX(filter(values(Calendar[Date]),[Total]>0),Calendar[Date])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Community Champion
Community Champion

@toum MAX('Table'[Date]). Am I missing something? Or maybe:

 

Measure = 

  VAR __Date = MAX('Dates'[Date])

  VAR __Result = MAXX(FILTER('Table',[Date] < __Date),[Date])

RETURN

  __Result



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you a lot for your help, but I need to include the min selected date of the slicer too, this means if the slicer is between 5/1/2021 and 10/1/2021 nothing will be returned because in the table there is no date between these 2 dates.

Hi , @toum 

According to your description, you want to create a date slicer and you need to get the max date in table in the selected date range you selected.

Here are teh steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1674009597344.png

(2)We can click "New Table" to  create a date table as a slicer:

Date SLicer = CALENDAR(FIRSTDATE('Table'[Date]) , LASTDATE('Table'[Date]))

(3)Then we can create a measure :

Max Date = var _min_date = MIN('Date SLicer'[Date])
var _max_date = MAX('Date SLicer'[Date])
var _t = FILTER(ALLSELECTED('Table') ,'Table'[Date]>=_min_date && 'Table'[Date]<= _max_date)
return
MAXX(_t ,[Date])

(4)Then we can put the filed we need on the visual and then we can meet your need the result is as follows:

vyueyunzhmsft_1-1674009658073.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

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.