Adding Drilldown in Query-Based Visuals

Let readers click a data point and see the detail underneath it.

⚠️ Prerequisite Filter Settings

Drilldown lets a reader click a data point — a bar in a chart, say — and see more detailed data underneath it, moving from a high-level summary to granular insight.

Building on the example from Filter Components with Query-Based Visuals, here is what a drilldown looks like:

ℹ️ What's Happening Here When the country "USA" is clicked, readers see the number of customers in each state within the USA. The same works for any country.
A drilldown from country into state

Setting this up takes four steps:

  1. Add the query that fetches the drilldown data
  2. Update that query to accept filters (hints), so it fetches only the relevant detail
  3. Save and refresh the visual
  4. Finish up

Step 1: Add a Drilldown Query

  • Open the query panel for the visual
  • Click + drill-down to add the query that fetches the drilldown data
Adding a drilldown query

Write the query that fetches state-wise data at Drill Down Level 1.

The initial drilldown query
The query still has no idea which states to fetch — that depends on the country the reader clicked. That's what the next step fixes.

Step 2: Make the Drilldown Query Accept Filters

If the reader clicks "USA", the WHERE clause needs country='USA'. Click "Canada", and it needs country='Canada'.

You pass a hint so PersivX can rewrite the query. The drilldown hint is written as :_harbour_drill_:<COLUMN>:undefined:.

ℹ️ Both Parts Matter The leading :_harbour_drill_: and the trailing :undefined: are both required for drilldown to work.

Before

SQL
SELECT state, COUNT(customerNumber) as numberOfCustomers
FROM [customers.xlsx]

GROUP BY state
ORDER BY COUNT(customerNumber) DESC

After

SQL
SELECT state, COUNT(customerNumber) as numberOfCustomers
FROM [customers.xlsx]
WHERE country=:_harbour_drill_:country:undefined:
GROUP BY state
ORDER BY COUNT(customerNumber) DESC

Finally, add every column used for drilldown to the SELECT clause as well. This lets PersivX place the new rows correctly in the current visual. Here we drill down on country, so it goes into both SELECT and GROUP BY.

Before

SQL
SELECT state, COUNT(customerNumber) as numberOfCustomers
FROM [customers.xlsx]
WHERE country=:_harbour_drill_:country:undefined:
GROUP BY state
ORDER BY COUNT(customerNumber) DESC

After

SQL
SELECT country, state, COUNT(customerNumber) as numberOfCustomers
FROM [customers.xlsx]
WHERE country=:_harbour_drill_:country:undefined:
GROUP BY country, state
ORDER BY COUNT(customerNumber) DESC

Step 3: Save and Refresh

Readers can now interact with the visual to see state-wise detail.

The working drilldown

Step 4: Finishing Up

Move the state attribute from "Show me" to "For every" to frame the story: for every country, then every state, show me the number of users.

Readers can now drill down into all countries at once.

Drilldown across all countries at once
⚠️ Known Issue Complete drilldown buttons sometimes fail to appear. This is a bug and will be fixed. For now, save and reload the report once — or ignore it and carry on with the next visual.

Important Points to Remember

If drilldown doesn't behave as expected, check that:

  • A drilldown query has been added
  • Drilldown hints have been passed in the WHERE clause
  • Columns used in the drilldown are also in the SELECT clause — most databases will require them in GROUP BY too for the query to be valid
💡 Next Continue to Multi-Attribute Drilldown to drill from and into several columns at once.