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
julesdude
Post Partisan
Post Partisan

Find the Nearest Future Date to User Selected Date

Hi all,
I have a table looking a little like this:

ReferenceDate
AAA12/05/2021
AAA20/12/2022
AAA01/02/2023
BBB01/12/2022
BBB04/02/2023

I need help with some DAX that essentially filters my table by the reference and returns the Date that is the nearest date in the future to today's date (or the [as of date] measure I have in my measures that itself finds the MAX value of a drop down date filter the user can use to select a date) 

I'm able to find solutions for this that involve creating a DAX column against a table in my model. However, this won't work for my case because the column would then not update when the user chooses a different date, as far as I understand it.

1 ACCEPTED SOLUTION

Hi @julesdude 

 

something like this?

FreemanZ_0-1670221350254.png

 

the code:

EarliestFutureDate =
VAR DateSelection =MIN('Calendar'[Date])
RETURN
CALCULATE(
    MIN(TableName[Date]),
    TableName[Date]>=DateSelection
)

View solution in original post

6 REPLIES 6
v-jialluo-msft
Community Support
Community Support

Hi  @julesdude ,

 

Please follow these steps:
(1) Create a new measure

FLAG = 
VAR _SELECT = IF(ISFILTERED('CALENDAR'[Date]),MAX('CALENDAR'[Date]),BLANK())
VAR _TABLE = CALCULATE(VALUES('Table'[Date]),TOPN(1,FILTER(ALL('Table'),'Table'[Date] >= _SELECT),'Table'[Date],ASC))
RETURN IF(MAX('Table'[Date] )= _TABLE ,1, 0)

(2)Apply filtering

vjialluomsft_0-1670223181163.png


(3)Final output

vjialluomsft_1-1670223225882.png

vjialluomsft_2-1670223259720.png

 

 

 

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

Thank you too @v-jialluo-msft 
It is a solution for someone else perhaps - just for me I needed a way without using a filter formula or DAX column scenario.

FreemanZ
Super User
Super User

hi @julesdude 

For the nearest future date per referencee, you may created column with the code below:

Column =
CALCULATE(
    MIN(TableName[Date]),
    ALLEXCEPT(TableName, TableName[Reference]),
    TableName[Date]>=TODAY()
)
 
I tried and it worked like this:
FreemanZ_0-1670056145373.png

 

for the (or the [as of date]....) part, not sure about your expectation. 

Hi @FreemanZ 

Many thanks for your reply.

Your line:
 TableName[Date]>=TODAY()

I am not sure your solution would work because TODAY() should not be used. The date used should be that selected by the user in the date picker I have provided in the report:

julesdude_0-1670203646994.png

I assigned the selection made here to the measure [As Of Date]:

As Of Date = CALCULATE(MAX(datetable[Date]), ALLSELECTED(DateTable))

I think if a DAX column is created for this solution then that column won't update dynamically when the date is changed byt the user....unless I am missing something??

 

Hi @julesdude 

 

something like this?

FreemanZ_0-1670221350254.png

 

the code:

EarliestFutureDate =
VAR DateSelection =MIN('Calendar'[Date])
RETURN
CALCULATE(
    MIN(TableName[Date]),
    TableName[Date]>=DateSelection
)

@FreemanZ thank you so much. A simple solution actually than I had thought!

The only change I made was to change the MIN('Calendar'[Date]) to MAX('Calendar'[Date]) to gain the user's selection from the date picker - I hide the first drop-down of this slicer from view so the user cannot change the minimum date in it.

Many thanks again!

 

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.