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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
darianle
Regular Visitor

Find the Nearest Value One column to Another Based on ID

Good Morning,

 

I have been wrapping my head around this for days—numerous searches to no avail.

 

I have three columns:   ID, Enter, and Exit

For Each ID,  if there is an Enter Time, there should be a corresponding Exit Time (nearest Value).

Could anyone provide a Dax for this?

 

In my sample below, I have provided an output column as to what the expected results should be.

 

thanks!

 

 

Sample Date

https://www.dropbox.com/s/h6dnh4h17luz50l/Sample%20Data.xlsx?dl=0

1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @darianle 

Try this calculated column:

ClosestExit = 
VAR enter_ = Table1[Enter]
RETURN
    TOPN (
        1,
        CALCULATETABLE (
            DISTINCT ( Table1[Exit] ),
            ALLEXCEPT ( Table1, Table1[NumberID] ),
            Table1[Exit] >= enter_
        ),
        Table1[Exit] - enter_, ASC
    )

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

Hi @darianle 

Try this calculated column:

ClosestExit = 
VAR enter_ = Table1[Enter]
RETURN
    TOPN (
        1,
        CALCULATETABLE (
            DISTINCT ( Table1[Exit] ),
            ALLEXCEPT ( Table1, Table1[NumberID] ),
            Table1[Exit] >= enter_
        ),
        Table1[Exit] - enter_, ASC
    )

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

WoW! that worked great.. 

 

The only issue now is: 

"<ccon>There's not enough memory to complete this operation. Please try again later when there may be more memory available.</ccon>"

 

But that's on me.

 

Thanks again

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.