Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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!
[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
@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.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
12 | |
11 | |
7 | |
6 |