Forum Discussion
Find the closest 3 items based on filter
- 4 years ago
Hi catrin_reach ,
1 Create a Parameter table for field. (used to select the factors)
Field Parameters in Power BI - Microsoft Power BI Community
2 Create a slicer table for school. (used to selecte the school name)
3 Create measure named "if closest 3 items"
if closest 3 items = VAR _s = SELECTEDVALUE ( Slicer[School Name] ) VAR _sfactors = MAX ( Parameter[Parameter] ) VAR _sr = CALCULATE ( SWITCH ( _sfactors, "% Boys", MAX ( 'Table'[% Boys] ), "% EAL", MAX ( 'Table'[% EAL] ), "% FSM", MAX ( 'Table'[% FSM] ), "% PP", MAX ( 'Table'[% PP] ), MAX ( 'Table'[% SEND] ) ), FILTER ( ALL ( 'Table' ), [School Name] = _s ) ) VAR _r = TOPN ( 3, FILTER ( ALLSELECTED ( 'Table' ), [School Name] <> _s ), ABS ( SWITCH ( _sfactors, "% Boys", [% Boys], "% EAL", [% EAL], "% FSM", [% FSM], "% PP", [% PP], [% SEND] ) - _sr ), ASC ) RETURN IF ( CONTAINS ( _r, 'Table'[School Name], SELECTEDVALUE ( 'Table'[School Name] ) ), 1, 0 )Then put it in filter pane and set it show item which is 1.
Then result:
Pbix file in the end you can refer.
Find the closest 3 items based on filter.pbix
Best regards.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi catrin_reach ,
1 Create a Parameter table for field. (used to select the factors)
Field Parameters in Power BI - Microsoft Power BI Community
2 Create a slicer table for school. (used to selecte the school name)
3 Create measure named "if closest 3 items"
if closest 3 items =
VAR _s =
SELECTEDVALUE ( Slicer[School Name] )
VAR _sfactors =
MAX ( Parameter[Parameter] )
VAR _sr =
CALCULATE (
SWITCH (
_sfactors,
"% Boys", MAX ( 'Table'[% Boys] ),
"% EAL", MAX ( 'Table'[% EAL] ),
"% FSM", MAX ( 'Table'[% FSM] ),
"% PP", MAX ( 'Table'[% PP] ),
MAX ( 'Table'[% SEND] )
),
FILTER ( ALL ( 'Table' ), [School Name] = _s )
)
VAR _r =
TOPN (
3,
FILTER ( ALLSELECTED ( 'Table' ), [School Name] <> _s ),
ABS (
SWITCH (
_sfactors,
"% Boys", [% Boys],
"% EAL", [% EAL],
"% FSM", [% FSM],
"% PP", [% PP],
[% SEND]
) - _sr
), ASC
)
RETURN
IF (
CONTAINS ( _r, 'Table'[School Name], SELECTEDVALUE ( 'Table'[School Name] ) ),
1,
0
)
Then put it in filter pane and set it show item which is 1.
Then result:
Pbix file in the end you can refer.
Find the closest 3 items based on filter.pbix
Best regards.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.