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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How to find an approximate value(Number) of a table

good morning everyone:
I have a table with distance values in kilometers, for example (0, 0.5, 1, 1.5, 2.1, 2.4, 2.8, 3.4, 3.6 ... etc) each distance value has an associated name. I have another table with other values in kilometers that increase by 0.1 (0, 0.1, 0.2, 0.3, 0.4 ... etc). This table the user can choose any value for example 3
I need that when the user chooses for example 3, it takes the closest value:

 

User choose: 3
distance result: 2.8

 

User choose: 2

distance result: 2.1


In excel VLOOKUP withTRUE is used for approximation

Any ideas?

Thank you!

2 REPLIES 2
daxer-almighty
Solution Sage
Solution Sage

[Closest Value] =
var __selectedVal = SELECTEDVALUE( Slicer[Value] )
var __output =
    if( NOT ISBLANK( __selectedVal ),
    
        // If there are 2 distances that are
        // equally close to the value but one
        // is below the value and one is above,
        // then choose the smaller one (below).
        MINX(
            TOPN(1, // can return 2 rows
                Distances, // this respects all filters present
                ABS( Distances[Value] - __selectedVal ),
                ASC
            ),
            Distances[Vaue]
        )
        
    )
return
    __output
camargos88
Community Champion
Community Champion

@Anonymous,

 

You need to have these tables disconnected. And use this measure:

_Number = 
VAR _selectedValue = SELECTEDVALUE(Km[Value])
VAR _tb = TOPN(1, ADDCOLUMNS(Distance, "Diff", ABS(_selectedValue - Distance[Distance])),[Diff], ASC)
RETURN SUMX(_tb, Distance[Distance])

 

Check the attached file.



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

Proud to be a Super User!



Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.