Forum Discussion
snph1777
6 years agoHelper V
Power BI - DAX language RANKX function for TOP 5 only
I have a Power BI table report as below. Products (dimension column) ProductCount (measure) ProductRank (measure) Fridge 36 1 AC 30 2 Fan 28 3 Light 25 4 Chair 20 5 ...
jdbuchanan71
6 years agoSuper User
I don't know of any way to do it with only measures. The reason being, you need somwhere that the value of 'Other' exists along with the list of products. That is a simple calculated table to create with code like this:
Product List =
UNION (
DISTINCT ( 'Product'[Product Name] ),
ROW("Product Name", "Other")
)
You join this new table into your existing product table and pull the product name from the new table for your report.
Then you can make a TopN measure that will show the top 5 and group the rest.
TopN =
VAR Top_N =
CALCULATETABLE ( 'Product List', TOPN ( 5, ALLSELECTED ( 'Product List' ), [Sales Amount] ) )
RETURN
IF (
NOT ISFILTERED ( 'Product List'[Product Name] ), CALCULATE ( [Sales Amount], ALLSELECTED ( 'Product List' ) ),
IF ( SELECTEDVALUE ( 'Product List'[Product Name] ) = "Other",
CALCULATE ( [Sales Amount], EXCEPT ( ALLSELECTED ( 'Product List' ), Top_N ) ),
CALCULATE ( [Sales Amount], INTERSECT ( 'Product List', Top_N ) )
)
)
In order to sort 'Other to the bottom of the list you would need a measure liks this and add it into your visual then set the column width narrow enough to hide it. It is just there to sort.
TopN Sort =
IF ( SELECTEDVALUE ( 'Product List'[Product Name] ) = "Other", 0, [TopN] )
- snph17776 years agoHelper V