Tableau / Basic: fields, models and views / Lesson 5
Filters, context and order of operations
Predict the population reaching aggregation, Top N and later calculations by tracing the query pipeline.
On this page
Lesson goals
- Distinguish filter stages.
- Compare Top N within a region with Top N overall.
- Separate filtering from authorization.
Name the filter stage
Tableau follows a defined pipeline rather than the order an author clicked controls. Extract and source filtering, context, ordinary dimension and measure filtering, LOD expressions and table calculations occupy different stages. Later lessons develop the calculation consequences. Begin by naming the population a filter should constrain. A prominent filter card does not automatically run before every calculation. An earlier restriction can remove data that no later selection restores. Preserve source scope and intended meaning before moving a filter, because making a result appear does not establish the right precedence.
Compare two top-product questions
Tea leads overall with 42, while North Coffee 18 exceeds North Tea 12. Global winner displayed in North and winner chosen within North are different questions. Under the documented pattern, a context filter can establish the region population before Top N. The first record states both answers without configuring a worksheet. Do not put every filter in context by habit: it changes semantics and can affect performance. Choose it because query precedence requires it, then verify the result with a small fixture whose global and regional rankings differ.
overall: Tea42 > Coffee18 -> Tea
North: Coffee18 > Tea12 -> Coffee
A: global winner displayed within North
B: winner selected after restricting to North
The winners differ because population selection occurs at a different stage. No Tableau filter is changed.
Distinguish row and group thresholds
A dimension selection can restrict contributing rows, while a measure filter can restrict aggregated groups at its stage. Filtering line Sales above 20 differs from retaining products whose SUM(Sales) exceeds 20. Tea has a 30 line and 42 total; Coffee has 18. Define threshold grain and whether excluded data should remain in a denominator or table calculation. A source restriction in a governed security design has different obligations from a consumer filter. Hiding a control alone is not enforcement. Later calculations may still need a population that is no longer visible, so document that requirement before filtering it away.
Trace precedence offline
The second program computes global and North product totals separately and selects each maximum. It reveals population differences without implementing Tableau’s entire pipeline. Define ties explicitly in real Top N requirements; they may need a documented secondary rule rather than an arbitrary winner. Compare the oracle with an authorized worksheet later. If it differs, inspect field scope, filter stage, sorting, Top settings and relationships before blaming the aggregation. Broadening filters until an expected number appears can conceal a wrong question and affect other sheets or calculations.
rows = [("North", "Tea", 12), ("North", "Coffee", 18), ("South", "Tea", 30)]
def totals(region=None):
result = {}
for place, product, amount in rows:
if region is None or place == region:
result[product] = result.get(product, 0) + amount
return result
global_totals = totals()
north = totals("North")
print(max(global_totals, key=global_totals.get))
print(max(north, key=north.get))
Tea
Coffee
Tea wins globally and Coffee in North. There is no tie and no source or worksheet access.
Review the visible contract
Test no selection, one region, multiple regions, empty results and a boundary threshold. Expose the population in titles or nearby explanation so readers know whether the winner is global or regional. Context is worksheet-specific and must not be assumed to govern every dashboard sheet. This course runs the small totals model only. Actual pipeline behavior, connector queries and filter security remain untested. A handoff should record each filter’s stage, purpose and expected contributing facts rather than treating a filter card as proof of scope or a hidden selection as access protection.
Common errors and fixes
Global winner is called regional winner
- Why it happens
- Top N and region used unintended precedence.
- How to fix it
- Define the population and use the documented context pattern when needed.
- Prevent it next time
- Test different global and regional winners.
Every filter becomes context automatically
- Why it happens
- Context was treated as a universal correction.
- How to fix it
- Review precedence and performance needs individually.
- Prevent it next time
- Document each context filter’s reason.
A group threshold is interpreted as a row threshold
- Why it happens
- Threshold grain and stage were unspecified.
- How to fix it
- State whether the rule targets lines or aggregated amounts.
- Prevent it next time
- Test a case where row and group results differ.
Check your understanding
1. Why can Tea win globally while Coffee wins in North?
Show worked solution
South 30 adds to North 12 for Tea 42 overall; Coffee has 18 in North. Restricting before ranking selects Coffee, while global ranking selects Tea. Both answer valid distinct questions. Specify precedence and label the population rather than judging one result wrong solely because the other looks more intuitive.
2. Why does hiding a filter not prove regional authorization?
Show worked solution
A hidden control is presentation state. Other sheets, edits, downloads or permitted paths can expose different data. Use the approved security design and test consumer permissions separately. The absence of an interactive choice cannot substitute for enforcing the allowed population at the appropriate governed layer.
Key takeaways
- Stage determines which population reaches a calculation.
- Context needs a documented analytical purpose.