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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
whatisdata96
Helper I
Helper I

How to find closest date after certain date in DAX? (Example shown)

Hi all -

 

I'm looking to create a conditional column in Power Query which would analyze 3 columns to output a 'looked up value' (date). This was probably not explained very well. But this is what I want:
image.png

 

I'm looking to return the NEXT nearest date for all rows with column 'type' = I. If it says, I, that means we want the next nearest date for where 'type' is O (matching with 'number'. For all rows with 'O' we can leave it as blank.

 

Is there a way to do this via condtional column? Or would I have to do a custom column in Power Query or DAX? Thank you in advance.

 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @whatisdata96 

Here are the steps you can refer to :

(1)My test data is the same as yours.

(2)We can create a calculated column in your table:

Column = var _cuurent_date = 'Table'[Date] 
var _tO =SELECTCOLUMNS( FILTER( 'Table' , 'Table'[Type]= "O") , "Date" , [Date])
var _compare =ADDCOLUMNS( CROSSJOIN( {_cuurent_date} , _tO) , "days" ,ABS( DATEDIFF([Date] ,[Value] ,DAY)))
var _min_days = MINX(_compare, [days])
var _mindate_table = DISTINCT( FILTER( _compare , [days] = _min_days))
return 
IF([Type]="I", CONCATENATEX(_mindate_table,[Date]), BLANK())

(3)Then we can meet your need , the result is as follows:

vyueyunzhmsft_0-1665713140364.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

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

2 REPLIES 2
Anonymous
Not applicable

HI

 

try this measure :

var daterech=selectedvalue(Table[Date])

return

calculate(Min(Table[Date]), filter(all(Table), Table[Date]>daterech))

v-yueyunzh-msft
Community Support
Community Support

Hi , @whatisdata96 

Here are the steps you can refer to :

(1)My test data is the same as yours.

(2)We can create a calculated column in your table:

Column = var _cuurent_date = 'Table'[Date] 
var _tO =SELECTCOLUMNS( FILTER( 'Table' , 'Table'[Type]= "O") , "Date" , [Date])
var _compare =ADDCOLUMNS( CROSSJOIN( {_cuurent_date} , _tO) , "days" ,ABS( DATEDIFF([Date] ,[Value] ,DAY)))
var _min_days = MINX(_compare, [days])
var _mindate_table = DISTINCT( FILTER( _compare , [days] = _min_days))
return 
IF([Type]="I", CONCATENATEX(_mindate_table,[Date]), BLANK())

(3)Then we can meet your need , the result is as follows:

vyueyunzhmsft_0-1665713140364.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

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
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Users online (25)