Forum Discussion
DarylRob
Helper I
4 years agoLookup closest value in table from parameter
So I've got a what if parameter where the user enters a value, I then want to lookup this value in a table of 1000 values and then return another column from the row with the closest value
I.e the table is
| 1 | 100,000 |
| 2 | 350,000 |
| 3 | 20,000 |
| 4 | 478,000 |
The user would enter 290,000 and it return 2. Is this possible?
Hi DarylRob ,
You can achieve this by using a difference between the what if and the table if you setup somehting similart to this:
Closest value = VAR temptable = TOPN ( 1, ADDCOLUMNS ( Table, "@Difference", ABS ( Table[Value] - 'Parameter'[Parater Value] ) ), [@Difference], ASC ) RETURN MINX ( temptable, Table[ID] )
2 Replies
- MFelix
Super User
Hi DarylRob ,
You can achieve this by using a difference between the what if and the table if you setup somehting similart to this:
Closest value = VAR temptable = TOPN ( 1, ADDCOLUMNS ( Table, "@Difference", ABS ( Table[Value] - 'Parameter'[Parater Value] ) ), [@Difference], ASC ) RETURN MINX ( temptable, Table[ID] )- DarylRob
Helper I
This is perfect, thank you