Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Creating a Top N and Others Table from related table (using Rankx)

Hello,

 

I'm trying to create a table showing say Top 5 Sales by Products and the balance in others. My tables are as follows:

 

SalesTable  
CustomerProductAmount
AAAA100
BBBB50
CCCC10
DAAA100

 

ProductsTable 
ProductDescription
AAA 
BBB 
CCC 

 

Intended output...

Ranked Product Table 
ProductSales
AAA200
BBB50
Others10



I have tried the solution here, but came across errors.
I am able to rank the products with the following formula:
Product Rank = RANKX(ALL('ProductsTable'[product]),SUMX(RELATEDTABLE('SalesTable'),'SalesTable'[Amount]))

I am unable to create the next formula:
Top 5 products = IF([Product Rank]<6,'ProductsTable'[product],"others") where i am unable to reference the column, 'ProductsTable'[product], either directly or using RELATED.

Does anyone know how to solve this?

2 Replies