Forum Discussion

bdog1971's avatar
bdog1971
Regular Visitor
4 years ago
Solved

Filter Ranking Table based off Slicer

I am a beginner to PowerBi and I need to filter my table by the Ranking column to only show the top 5 records, top 10 records, top 15 records, bottom 5 records, bottom 10 record.    Table Below.  

 

Thanks

 

RankingProjectTypeRiskThreats 
1Project 1GovernanceSignificantMajor
2Project 2ProjectSignificantMajor
3Project 3GovernanceSignificantMajor
4Project 4ProjectSignificantMajor
5Project 5ProjectMajorMajor
6Project 6GovernanceSignificantMajor
7Project 7ProjectSignificantMajor
8Project 8ProjectMajorMajor
9Project 9ProjectModerate Major
10Project 10ProjectMajorMajor
11Project 11ProjectMajorMajor
12Project 12ProjectSignificantMajor
13Project 13ProjectSignificantMajor
14Project 14ProjectSignificantMajor
15Project 15ConsultingMajorMajor
16Project 16ProjectMajorMajor
17Project 17ProjectMajorMajor
18Project 18GovernanceMajorMajor
19Project 19ConsultingMajorMajor
20Project 20ProjectMajorMajor
21Project 21ProjectUnspecifiedMajor
22Project 22ProjectModerate Moderate
23Project 23ProjectUnspecifiedMajor
24Project 24ProjectMajorMajor
25Project 25ConsultingModerate Moderate
26Project 26ConsultingMinorModerate
27Project 27ProjectModerate Major
28Project 28ConsultingModerate Moderate
29Project 29ConsultingUnspecifiedMajor
30Project 30GovernanceUnspecifiedMajor
31Project 31ConsultingUnspecifiedMajor
32Project 32ConsultingMajorMajor
33Project 33ProjectUnspecifiedMajor

 

 

  • smpa01's avatar
    smpa01
    4 years ago

    bdog1971  you can use this

    Measure =
    VAR _AscendingOrder =
        RANKX ( ALLSELECTED ( t1 ), CALCULATE ( MAX ( t1[Ranking] ) ),, ASC )
    VAR _DescendingOrder =
        RANKX ( ALLSELECTED ( t1 ), CALCULATE ( MAX ( t1[Ranking] ) ),, desc )
    VAR _selection =
        SWITCH (
            TRUE (),
            CONTAINSSTRING ( SELECTEDVALUE ( 'New-Slicer'[Category] ), "Bottom" ), _AscendingOrder,
            _DescendingOrder
        )
    VAR _value =
        IF ( _selection <= SELECTEDVALUE ( 'New-Slicer'[Value] ), _selection )
    VAR _select =
        SELECTEDVALUE ( 'New-Slicer'[Category] )
    RETURN
        IF ( _select = BLANK (), MAX ( t1[Ranking] ), _value )
    

     

     

10 Replies

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    bdog1971  you can use a measure like this

    Measure = 
    VAR _AscendingOrder = RANKX(ALLSELECTED(t1),calculate(MAX(t1[Ranking])),,ASC)
    VAR _DescendingOrder = RANKX(ALLSELECTED(t1),calculate(MAX(t1[Ranking])),,desc)
    VAR _selection =
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( 'New-Slicer'[Category] ) = "Bottom10"
                || SELECTEDVALUE ( 'New-Slicer'[Category] ) = "Bottom20"
                || SELECTEDVALUE ( 'New-Slicer'[Category] ) = "Bottom5", _AscendingOrder,
            _DescendingOrder
        )
    VAR _value =
        IF ( _selection <= SELECTEDVALUE ( 'New-Slicer'[Value] ), _selection )
    RETURN
        _value

    pbix is attached

     

    • AlexisOlson's avatar
      AlexisOlson
      Icon for Super User rankSuper User

      Looks good. I'd suggest not hard-coding the specific category values though.

      VAR _selection =
          IF (
              CONTAINSSTRING ( SELECTEDVALUE ( 'New-Slicer'[Category] ), "Bottom" ),
              _AscendingOrder,
              _DescendingOrder
          )

       

    • bdog1971's avatar
      bdog1971
      Regular Visitor

      What do I need to add so when nothing is selected in the slicer that is shows me all the records instead of no records?  Sorry I shuold have added that in my explanation?

       

      Thank you so much for the help.  

      • smpa01's avatar
        smpa01
        Icon for Community Champion rankCommunity Champion

        bdog1971  you can use this

        Measure =
        VAR _AscendingOrder =
            RANKX ( ALLSELECTED ( t1 ), CALCULATE ( MAX ( t1[Ranking] ) ),, ASC )
        VAR _DescendingOrder =
            RANKX ( ALLSELECTED ( t1 ), CALCULATE ( MAX ( t1[Ranking] ) ),, desc )
        VAR _selection =
            SWITCH (
                TRUE (),
                CONTAINSSTRING ( SELECTEDVALUE ( 'New-Slicer'[Category] ), "Bottom" ), _AscendingOrder,
                _DescendingOrder
            )
        VAR _value =
            IF ( _selection <= SELECTEDVALUE ( 'New-Slicer'[Value] ), _selection )
        VAR _select =
            SELECTEDVALUE ( 'New-Slicer'[Category] )
        RETURN
            IF ( _select = BLANK (), MAX ( t1[Ranking] ), _value )
        

         

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    I would say there are several ways to get desired output, but based on the question I'm not sure if you want many tables, visual or other output. Just by loading your table to PBI you can use the ranking in a slicer:

    or as a filter in the filter pane:

    or to the table it's self as  a "TOP N" using TOP/BOTTOM:

     

     

    • bdog1971's avatar
      bdog1971
      Regular Visitor

      The top one would be the best for what I am doing.    I was trying not to hard code the values but let the reader of the report be able to select what they wanted.