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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
catrin_reach
Frequent Visitor

Find the closest 3 items based on filter

I have 60 schools, and I want users to be able to select a school and see a number of different factors like the proportion of boys, receiving free meals etc in one bar chart, and then I want another bar chart below it to show the 3 schools in the data set with the closest values to the chosen schools figure. This needs to update everytime the users picks a new school. Ideally there would also be a text box that contains the name of the school that appears most frequently in the top 3 boxes of all the measures. I am pretty new to PowerBI so grateful for any help. thanks. examples/data below. 

 

School Name% Boys% EAL% FSM% PP% SEND
School 150%37%41%42%17%
School 244%4%46%47%19%
School 343%20%14%15%5%
School 445%1%33%36%8%
School 548%48%68%69%15%

 


Example of what I want to showExample of what I want to show

 

1 ACCEPTED SOLUTION
ChenwuZhu_Gmail
Resolver I
Resolver I

Hi @catrin_reach ,

 

1 Create a Parameter table for field. (used to select the factors)

Field Parameters in Power BI - Microsoft Power BI Community

ChenwuZhu_Gmail_0-1660210372915.png

 

2 Create a slicer table for school. (used to selecte the school name)

ChenwuZhu_Gmail_1-1660210389914.png

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.

ChenwuZhu_Gmail_2-1660210535412.png

 

Then result:

ChenwuZhu_Gmail_3-1660210555320.png

 

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.

 

View solution in original post

1 REPLY 1
ChenwuZhu_Gmail
Resolver I
Resolver I

Hi @catrin_reach ,

 

1 Create a Parameter table for field. (used to select the factors)

Field Parameters in Power BI - Microsoft Power BI Community

ChenwuZhu_Gmail_0-1660210372915.png

 

2 Create a slicer table for school. (used to selecte the school name)

ChenwuZhu_Gmail_1-1660210389914.png

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.

ChenwuZhu_Gmail_2-1660210535412.png

 

Then result:

ChenwuZhu_Gmail_3-1660210555320.png

 

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.

 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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