Forum Discussion

Chris_68's avatar
Chris_68
Helper I
1 year ago
Solved

Help with increase of displayed data

Hi! I’m using a ranking measure to limit the number of line items displayed in a table. However, when I add the "Minor" field to the table, it increases the number of displayed items beyond the sp...
  • sanalytics's avatar
    1 year ago

    Chris_68 
    I am not sure regarding your exact requirement and desired output.Are you looking for top 10 qty including item and minor?? if yes. then you can try the below code

    Rank = 
    VAR _Rank =
    RANKX(
     ALL( Parts[Item],Parts[Minor] ),[TotalQty],,DESC )
    VAR _Result = 
    IF(
     _Rank <= [TopN Value],1 )
     RETURN
     _Result

    below screenshot

     

    Regards

    sanalytics



  • DataNinja777's avatar
    1 year ago

    Hi Chris_68 ,

     

    This is a common issue in DAX caused by how filter context works in Power BI. When you add the Minor column to your table, you change the context for each row from just an Item to a unique combination of Item and Minor. Your original ranking measure is then evaluated in this new, more detailed context, which causes more rows to appear than you intended.

     

    To resolve this, you need to modify your Rank By Item measure to ignore the filter context coming from the Minor column. This is done by wrapping the [TotalQty] argument inside a CALCULATE function. This ensures the ranking is always based on the total quantity for the entire Item, regardless of what other details like Minor are present in the table. Your other measures can remain the same.

    Your current formula is:

    Rank By Item = RANKX ( ALL ( Parts[Item] ), [TotalQty],, DESC )

    You should update it to the following corrected formula:

    Rank By Item =
    RANKX (
        ALL ( Parts[Item] ),
        CALCULATE ( [TotalQty], ALL ( Parts[Minor] ) ),
        ,
        DESC
    )
    

    After making this one change, your table visual will correctly filter to the Top N items first and then display their associated Minor codes, matching your intended result.

     

    Best regards,