Forum Discussion

KN8's avatar
KN8
Frequent Visitor
4 years ago
Solved

Top N filter + other

Hello Everyone,   I'm trying to achive TOP 3 + Other(Oracle) Companies by revenue  from the below table. I was able to get Top 3 by applying TOP N filter on the visual.  How can we achieve  TOP N ...
  • Jihwan_Kim's avatar
    4 years ago

    Hi,

    Please check the below picture and the attached pbix file.

     

     

    Only show top3 and Oracle: =
    VAR top3table =
    TOPN ( 3, ALL ( Data[Companies] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
    RETURN
    IF (
    HASONEVALUE ( Data[Companies] ),
    SWITCH (
    TRUE (),
    SELECTEDVALUE ( Data[Companies] ) = "Oracle", SUM ( Data[Revenue] ),
    CALCULATE ( SUM ( Data[Revenue] ), KEEPFILTERS ( top3table ) )
    )
    )

     

     

  • Jihwan_Kim's avatar
    Jihwan_Kim
    4 years ago

    Hi, 

    Thank you for your message.

    When you see the previous measure, there is a IF condition that says "if there is one company in the row, then show the result, otherwise blank".

    if I do not write this, then it shows the wrong total, and I did not know whether readers want to see the total or not. I thought showing blank is better than showing a wrong total.

    If you want to show the total, then please try the below.

     

    Only show top3 and Oracle: =
    VAR top3table =
    TOPN ( 3, ALL ( Data[Companies] ), CALCULATE ( SUM ( Data[Revenue] ) ), DESC )
    RETURN
    SUMX (
    VALUES ( Data[Companies] ),
    CALCULATE (
    SWITCH (
    TRUE (),
    SELECTEDVALUE ( Data[Companies] ) = "Oracle", SUM ( Data[Revenue] ),
    CALCULATE ( SUM ( Data[Revenue] ), KEEPFILTERS ( top3table ) )
    )
    )
    )