Approach summary: build two parameters (N and Mode), compute rank by revenue at the desired grain using an LOD or table calculation, then filter to rank ≤ N (Top) or rank ≥ (maxRank - N +1) for Bottom. For 100M rows, push aggregation to the source and use extracts/context filters to reduce rows before ranking.Parameters:- N (Integer) range 1–20, default 10- Mode (String) values: "Top by Revenue", "Bottom by Revenue"Key calculated fields:1) Aggregate revenue at dimension grain (use LOD to guarantee correct ranking independent of view):sql
// Total Revenue per [Category]
{ FIXED [Category] : SUM([Revenue]) }
2) Rank by revenue (descending):sql
// Rank Desc
RANK_UNIQUE( SUM([Revenue]) , 'desc')
(If using LOD use WINDOW_RANK on the LOD: WINDOW_RANK(SUM([LOD Revenue]), 'desc') when using table calcs.)3) Dynamic filter logic:sql
// Keep Flag
IF [Mode] = 'Top by Revenue' THEN
[Rank Desc] <= [N]
ELSE
[Rank Desc] >= (TOTAL(COUNTD([Category])) - [N] + 1)
END
(For table calculation implementations compute max rank via WINDOW_MAX or use a separate INDEX logic.)Filter steps:- Place the "Keep Flag" on Filters and set to True.- If using table calculations (WINDOW_RANK), ensure compute using the dimension (e.g., Category) and turn the filter into a table calculation (use a table calc filter) — apply it after table calc by using it on Filters shelf but set to "Show only relevant values" or use a boolean pill with “Compute Using” configured.- Prefer LOD approach: create LOD revenue and use RANK() on that; put Rank on Filter.Performance considerations (100M rows):- Push aggregation to the source: use a derived table or pre-aggregated materialized view that computes SUM(Revenue) by Category. Rank on the aggregated result reduces rows dramatically.- Use extracts (Hyper) with aggregation at extract time (Extract > Aggregate data for visible dimensions).- Use Context Filters sparingly to filter high-cardinality dimensions before rank; context filters are applied before normal filters and can speed table calcs.- Avoid row-level table calculations over 100M rows; they are expensive. Prefer database-side SQL or LOD expressions combined with extracts.- Limit returned columns and use indexing/partitioning in DB on join keys used for aggregation.- Test performance with representative sample, monitor query times, and consider caching or nightly pre-computation of top-N in the warehouse if interactive latency is unacceptable.Notes/alternatives:- Use a Set action + parameter to let users interactively choose Top N from the viz.- For multiple dimensions consider concatenated keys in the LOD.This gives a responsive, user-controlled Top/Bottom N while respecting Tableau performance best practices.