Use an existing report to filter a new report

For example, my client wants to know who purchased an item in a particular category on their first purchase.

Then from there they want to see another report that shows how many other products did those customers purchase.

This is easy in SQL with temp tables.

Would love this feature for a few dynamic reports.

Hi Sehab,

Thank you for your request. We don’t currently have the exact functionality you described, but I’m pleased to inform you that we can accommodate your request using AQL. Here’s how you can achieve similar results:

  1. To identify customers who made their first purchase in a particular category: (link)
unique(users.id, orders.id, categories.name) 
| filter(
    rank(
      partition: users.id, 
      order: min(orders.created_at) | of_all(categories.name)
    ) == 1
  )
| filter(categories.name == '[Your Category]')
  1. To then see how many other products these customers purchased:
count(products.id) | where(
  users.id in (
    unique(users.id, orders.id, categories.name) 
    | filter(
        rank(
          partition: users.id, 
          order: min(orders.created_at) | of_all(categories.name)
        ) == 1
      )
    | filter(categories.name == '[Your Category]')
  )
)

You can see this query in action and experiment with it further here: [Link to query playground]

How do I add this as part of a condition when building the visualization.
Something like this:

Hi Sehab,

We don’t support using custom AQL as a filter yet. But in this case, you can put the whole thing into a metric.

Regards,