# Setting a Baseline Run

The "Baseline Run" is a core concept in DBNL that, appropriately, refers to the Run used as a baseline when executing a Test Session. Conversely, the Run being tested is called the "Experiment Run". Any [tests you've created](https://docs.dbnl.com/v0.23.x/using-distributional/tests/creating-tests) that compare statistics will test the values in the experiment relative to the baseline.

## Dynamic Baseline (Run Queries)

Depending on your use case, you may want to make your Baseline Run dynamic. You can use a Run Query for this. Currently, DBNL supports setting a Run Query that looks back a number of previous runs. For example, in a production testing use case, you may want to use the previous Run as the baseline for each Test Session, so you'd create a Run Query that looks back `1` run. See the UI example in the [Setting a Default Baseline Run](#setting-a-default-baseline-run) section for information on how to create a Run Query. You can also create a Run Query [via the SDK](https://docs.dbnl.com/v0.23.x/reference/python-sdk).

## Setting a Default Baseline Run

{% hint style="info" %}
You can choose a Baseline Run at the time of Test Session creation. If you do not provide one, DBNL will use your Project's default Baseline Run. See [Running Tests](https://docs.dbnl.com/v0.23.x/using-distributional/tests/running-tests) for more information.
{% endhint %}

You can set a default Baseline Run to be used in all Test Sessions either via the UI or the SDK. Additionally, you can create a Run Query to make your Baseline Run dynamic for each Test Session.

{% tabs %}
{% tab title="UI" %}
From your Project, click the "Test Configuration" tab. Choose a Run or Run Query from the Baseline Run dropdown.

<figure><img src="https://content.gitbook.com/content/OMjGNg2NTV4gBwKOIb1S/blobs/fGoIUItlpUwMYGS2jIwy/image.png" alt=""><figcaption><p>From your Project, click "Test Configuration" and select a Baseline Run in the dropdown.</p></figcaption></figure>
{% endtab %}

{% tab title="SDK" %}
You can set a Run as baseline via the `set_run_as_baseline` or `set_run_query_as_baseline` functions.

```python
import dbnl

# Get a reference to a Run either by creating one or fetching by ID
run = dbnl.get_run(run_id="run_abc123") # or dbnl.report_result_with_results
dbnl.set_run_as_baseline(run=run)

# You can also use a Run Query for a dynamic baseline
project = dbnl.get_or_create_project(name="My Project")
run_query = dbnl.create_run_query(
  project=project,
  name="Look back 3 runs",
  query={
    "offset_from_now": 3,
  },
)
dbnl.set_run_query_as_baseline(run_query=run_query)
```

{% endtab %}
{% endtabs %}
