# Custom "Explore" Queries

Custom queries run additional experiment analyses on your existing data beyond what's in your main Results tab. Use them to gain deeper insights from experiments and feature rollouts, debug interesting results, or scope results to specific sub-groups. Custom queries let you filter or group metrics by event or user dimensions. You can also filter to a specific set of users to see how an experiment or launch affected those users.

Custom queries are experimental analyses, and all the same statistical procedures apply as in the main Results tab. Statsig computes results as p-values and confidence intervals for your metric deltas. You can also use advanced statistical methods like [CUPED](https://docs.statsig.com/experiments/statistical-methods/methodologies/cuped) and [Sequential Testing](https://docs.statsig.com/experiments/advanced-setup/sequential-testing).

{% callout type="warning" %}
Use caution when drawing inferences from Custom Queries, especially when grouping by a dimension with many options. This increases the chance of a false-positive statistically significant result.
{% /callout %}

### Dimension loading timing for precomputed user dimensions

When viewing results for precomputed user dimensions (which you configure and run on a schedule), Statsig loads these dimensions through separate asynchronous explore queries. This means:

- The main experiment results appear first.
- Precomputed dimensions continue loading in the background and appear within a few minutes.
- This timing gap is most noticeable immediately after the first reload of the day.
- If you see "No dimensions available for this time range" for precomputed dimensions, wait a few minutes and refresh to check whether dimensions have finished loading.

{% callout type="note" %}
This timing behavior only affects precomputed user dimensions that run on a schedule. User-triggered custom queries don't experience this asynchronous loading delay.
{% /callout %}

### Running a custom query

To run a custom query, go to the **Explore** tab within your experiment.

{% figure %}
<img src="https://docs.statsig.com/images/snippets/pulse/custom-queries/b2737ba1-dbf4-4235-a806-afea5dfe9a78.png" alt="Custom query explore tab interface" width="467" />
{% /figure %}

Custom Query fields:

- **Metric(s)**: The metric(s) you want to analyze. You can select a single metric, a few metrics, or a Metric Tag. Adding a Tag includes all the metrics within that Tag in your Custom Query. There are three "default" metric selections included as shortcuts:
  - "Scorecard Metrics", all metrics included in your experiment setup's Primary and Secondary Metrics sections
  - "Primary Metrics"
  - "Secondary Metrics"
- **Metric Filter**: With metrics selected, you can filter metrics by either Event or User dimensions using the "Add Filter" dropdown. For example, to view experiment results for Canadian users only, filter to "Country = CA".

{% figure %}
![Metric filter dropdown selecting Country equals CA](https://docs.statsig.com/images/snippets/pulse/custom-queries/f56b4259-4d18-44d1-9646-9d7aa2f8f847.png)
{% /figure %}

- **Group By**: You can group your custom query results by either an Event or User dimension. You can apply custom query filters at the _per-metric_ level. The Group By action is at the _query_ level, so all included metrics have the Group By you select applied to them.
- **Time Range for Metric Data**: The date range you're running your analysis on. By default this is the "Full date range" of your experiment data.
- **(Advanced) ID List Segment filters**: You can choose an ID-list based [Segment](https://docs.statsig.com/segments/overview), and Statsig calculates your results only for users in that segment. This is useful when you didn't log an important user dimension to filter on, or when you only need results for a sub-population defined in your own data warehouse.
  - This option can easily lead to erroneous and biased results. You must define the segment based on the user's status _before_ their exposure to the experiment or feature gate.
  - You can also choose to _exclude_ a certain ID list segment. For example, exclude users you've retroactively identified as bad actors from your lifts analysis.
- **(Advanced) Filter by Exposure Date**: You can also filter the results by Exposure Date for more flexibility. You can include or exclude a date range, or in WHN, include/exclude users based on their first exposure to the experiment.
  - This is useful when your metrics have a novelty effect, delayed impact, or when you need to filter results to specific users. Use it cautiously because it can lead to biased results.

{% callout type="note" %}
User groups in experiment results are based on first-touch attribution. Filters and grouping are based on the user attributes collected at the time of first exposure in the gate/experiment/layer check.
{% /callout %}

{% figure %}
<img src="https://docs.statsig.com/images/snippets/pulse/custom-queries/85264260-2f65-4bfd-b4e1-477bd043b87d.png" alt="Custom query definition form showing selected metrics and filters" width="1378" />
{% /figure %}

### Viewing a custom query in Explore

These queries take a few minutes to run. After the query completes, Statsig sends an email notification and the results appear in the **Query History** section of the *Explore* interface. Statsig stores all historical queries across your team there. You can assign a display name to a query inline for easier future identification.

{% figure %}
<img src="https://docs.statsig.com/images/snippets/pulse/custom-queries/46574581-604e-4d29-b231-fa51876c813d.png" alt="Explore tab query history list" width="1374" />
{% /figure %}

### Scheduling a custom query

To get a daily refresh of a custom query, schedule it directly from the **Explore** tab. Create the custom query, then select the "..." menu, then **Schedule**. The custom query runs daily and appears in the **Scheduled** tab of your Metric Lifts.

{% figure %}
<img src="https://docs.statsig.com/images/snippets/pulse/custom-queries/56d11b46-f2de-4569-89f7-b0a439910964.png" alt="Scheduled custom queries tab displaying daily runs" width="1378" />
{% /figure %}

{% figure %}
<img src="https://docs.statsig.com/images/snippets/pulse/custom-queries/fad0c8ce-3f9c-46be-a09c-52263e124259.png" alt="Scheduled query configuration interface" width="505" />
{% /figure %}

### Reviewing custom query results

Custom query results resemble the main Results tab because the statistical methods are the same. The key difference is that a custom query result is a snapshot in time. After a query runs, Statsig saves the results and doesn't update them when more metric data arrives. To update results, run a new custom query or schedule custom queries to run on a regular cadence.

#### Sequential testing and custom queries

If you enable [Sequential Testing](https://docs.statsig.com/experiments/advanced-setup/sequential-testing) for your experiment, it applies to custom query results as well. The degree of adjustment to confidence intervals and p-values follows the standard sequential testing rules. If a custom query doesn't satisfy the experiment's target Days or Unique Exposures from your setup, Statsig applies sequential testing adjustments to account for the underpowered state of the experiment.

Because custom queries are snapshots in time, sequential testing adjustments apply to that specific analysis only. Running additional custom queries with more or less data (for example, more days or more unique users) changes the adjustments accordingly. Custom queries that meet the configured minimum Days or Unique Exposures may have no sequential adjustments applied.

{% figure %}
![Custom query results table displaying sequential testing adjustments](https://docs.statsig.com/images/snippets/pulse/custom-queries/df7c4087-82c3-41fb-8f5d-124094ec4526.png)
{% /figure %}
