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

Find nearest value in column greater than X (variable)

Hello there,

I can't find a way to get the nearest value in a column, which is greater than X (variable). The entire evaluation is within the same table.

Details:

I need to evaluate data stored in column name: Age Index (decimal), associated with column: Weight

then I need to create two new columns:

Evaluation & Evaluated weight

 

for the Evaluation column:

VAR AgeIndexDiff = 1 # I will use it for for a slicer filter in next stage

Evaluation = (nearest value of the first NonBlank row in Age Index column) >= ( "current row value of Age Index" + AgeIndexDiff)

 

for the Evaluated weight column:

Evaluated weight = associated Weight from the Evaluation row value

 

Data Sample (as-is):

Age IndexWeight
7.7215.29
7.8715.91
8.2517.91
8.3617.95
8.7318.57
8.8220.17
9.620.57
9.1322.16
9.2922.75
9.5825.35
9.6326.86
9.6727.52
9.7127.69
9.8129.57
9.9430.68
9.9931.62
10.2232.93
10.4733.2
10.736.66
1137.68
11.2238.21
11.4738.53
11.6339.54
12.1540.59
12.2342.38
12.4246.22
12.5647.74
12.9548.21
13.248.52
13.5149.05
13.750.39
13.8450.44
14.951.19
14.3152.59

 

Data to-be stage (when VAR = 1):

Age IndexWeightEvaluationEvaluated weight
7.7215.298.7318.57
7.8715.918.8220.17
8.2517.919.2922.75
8.3617.959.2922.75
8.7318.579.7127.69
8.8220.179.8129.57
9.620.579.9931.62
9.1322.1610.2232.93
9.2922.7511.2238.21
9.5825.3510.4733.2
9.6326.8610.736.66
9.6727.5210.736.66
9.7127.6910.736.66
9.8129.5710.736.66
9.9430.68  
9.9931.62  
10.2232.93  
10.4733.2  
10.736.66  
2 ACCEPTED SOLUTIONS
AllisonKennedy
Super User
Super User

@jeyare  You should be able to do this with the MINX function, however the part where you want to use a slicer won't work with a calculated column: https://excelwithallison.blogspot.com/2020/09/reporting-order-of-operations.html

 

In order for it to update with slicers, you'd need to create them as a MEASUREs

 

Evaluation =

VAR _CurrentAgeIndex = SELECTEDVALUE(DataTable[Age Index])

VAR _AgeIndexDiff = SELECTEDVALUE(SlicerTable[Diff])

RETURN

MINX(FILTER(DataTable, DataTable[Age Index] >= _CurrentAgeIndex + _AgeIndexDiff ),  DataTable[Age Index] )

 

Evaluated Weight =

VAR _CurrentAgeIndex = SELECTEDVALUE(DataTable[Age Index])

VAR _AgeIndexDiff = SELECTEDVALUE(SlicerTable[Diff])

VAR _Evaluation = 

MINX(FILTER(DataTable, DataTable[Age Index] >= _CurrentAgeIndex + _AgeIndexDiff ),  DataTable[Age Index] )

RETURN

MINX(FILTER(DataTable, DataTable[Age Index] = _Evaluation), DataTable[Weight] )

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

Thx Allison,

works great with some tunes, when I calculate MIN and MAX values to find the nearest possible difference in ABS value (+ or -)

View solution in original post

2 REPLIES 2
AllisonKennedy
Super User
Super User

@jeyare  You should be able to do this with the MINX function, however the part where you want to use a slicer won't work with a calculated column: https://excelwithallison.blogspot.com/2020/09/reporting-order-of-operations.html

 

In order for it to update with slicers, you'd need to create them as a MEASUREs

 

Evaluation =

VAR _CurrentAgeIndex = SELECTEDVALUE(DataTable[Age Index])

VAR _AgeIndexDiff = SELECTEDVALUE(SlicerTable[Diff])

RETURN

MINX(FILTER(DataTable, DataTable[Age Index] >= _CurrentAgeIndex + _AgeIndexDiff ),  DataTable[Age Index] )

 

Evaluated Weight =

VAR _CurrentAgeIndex = SELECTEDVALUE(DataTable[Age Index])

VAR _AgeIndexDiff = SELECTEDVALUE(SlicerTable[Diff])

VAR _Evaluation = 

MINX(FILTER(DataTable, DataTable[Age Index] >= _CurrentAgeIndex + _AgeIndexDiff ),  DataTable[Age Index] )

RETURN

MINX(FILTER(DataTable, DataTable[Age Index] = _Evaluation), DataTable[Weight] )

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Thx Allison,

works great with some tunes, when I calculate MIN and MAX values to find the nearest possible difference in ABS value (+ or -)

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.