Forum Discussion

Lefuneste57's avatar
Lefuneste57
Icon for Helper I rankHelper I
2 years ago
Solved

How to create a segment with N first line from a table report order bye amount value ?

Hi, i have make a report with this data for exemple,i have many segment filter in my page. So i would know how can i make a segment filter to choose the number of  line (order by amount) to disp...
  • mark_endicott's avatar
    2 years ago

    Lefuneste57 - Just to clarify, my solution will work for you & it is dynamic (because it uses a measure), so the ranking will be re-calculated according to any filters you use on the page. 

     

    But you will need to use the measure below in any visual that you want to see this behaviour. There is no need to use a page filter because the measure handles the visual filtering. So if you want to filter an entire page, place the measure in every visual. 

     

    It works by only displaying the amount value when the rank number is lower than or equal to the number in the slicer. The slicer is created using these instructions: https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-what-if

     

     

    VAR Number_to_Rank = [Number of Lines (by order amount) Value] // from the numeric range parameter
    VAR _amount = [_amount] // sum( amount )
    RETURN
        IF (
            RANKX ( ALLSELECTED ( 'Table (6)'[Item], 'Table (6)'[Build] ), [_amount] ) <= Number_to_Rank,
            _amount
        ) // Returns the amount for any items that with a rank within the numbers specified in the Numeric range parameter.