Forum Discussion
Top 10 excluding value
- 8 months ago
Hi jwdal,
Try this instead it will work:In Top 10 = VAR CustomersWithoutExclude = FILTER( ALL(AC_ALL[Top10]), AC_ALL[Top10] <> "EXCLUDE" ) VAR Top10Customers = TOPN( 10, CustomersWithoutExclude, [Net Sales], DESC ) RETURN CALCULATE( [Net Sales], KEEPFILTERS(AC_ALL[Top10] IN Top10Customers) )
Hi jwdal,
The Issue here is that when the excluded customer is in the top 10 you are ranking only 9 customers with ranks 1-9 but checking for ≤10 so you only get 9 results....Here are two better Approaches you can try:
First Approach:Rank first then exclude (most robust)
In Top 10 =
VAR AllCustomers = ALL(AC_ALL[Top10])
VAR ExcludedValue = "EXCLUDE"
VAR RankedCustomers =
ADDCOLUMNS(
AllCustomers,
"Rank", RANKX(AllCustomers, [Net Sales], , DESC),
"Sales", [Net Sales]
)
VAR Top10Customers =
FILTER(
RankedCustomers,
[Rank] <= 10 && [Top10] <> ExcludedValue
)
VAR ResultCustomers =
TOPN(
10,
Top10Customers,
[Sales], DESC
)
RETURN
CALCULATE(
[Net Sales],
TREATAS(VALUES(SELECTCOLUMNS(ResultCustomers, "Customer", [Top10])), AC_ALL[Top10])
)
Second Approach:Using TOPN with exclusion (cleanest and most efficient one)
In Top 10 =
VAR CustomersWithoutExclude =
FILTER(
ALL(AC_ALL[Top10]),
AC_ALL[Top10] <> "EXCLUDE"
)
VAR Top10Customers =
TOPN(
10,
CustomersWithoutExclude,
[Net Sales], DESC
)
RETURN
CALCULATE(
[Net Sales],
KEEPFILTERS(AC_ALL[Top10] IN VALUES(Top10Customers[Top10]))
)
Got an error message
Cannot find table 'Top10Customers'
- Ahmed-Elfeel8 months agoSuper User
Hi jwdal,
Try this instead it will work:In Top 10 = VAR CustomersWithoutExclude = FILTER( ALL(AC_ALL[Top10]), AC_ALL[Top10] <> "EXCLUDE" ) VAR Top10Customers = TOPN( 10, CustomersWithoutExclude, [Net Sales], DESC ) RETURN CALCULATE( [Net Sales], KEEPFILTERS(AC_ALL[Top10] IN Top10Customers) ) - amitchandak8 months agoSuper User
jwdal , Create a measure with what ever you want to exlcude
Filter M = CALCULATE([Net Sales], keepfilters(AC_ALL[Top10] <> "EXCLUDE"))
Top 10 = CALCULATE([Filter M], KEEPFILTERS(TOPN(10, ALL( AC_ALL[Top10]), [Filter M], DESC)))
Top 10 = CALCULATE([Filter M], KEEPFILTERS(Window(0,ABS,10,ABS, ALL( AC_ALL[Top10]),ORDERBY([Filter M],Desc))))or
Top 10 = CALCULATE([Filter M], KEEPFILTERS(TOPN(10, allselected( AC_ALL[Top10]), [Filter M], DESC)))
Top 10 = CALCULATE([Filter M], KEEPFILTERS(Window(0,ABS,10,ABS, allselected( AC_ALL[Top10]),ORDERBY([Filter M],Desc))))