# Exclude model from dbt run by default but still want to run the model separately

**URL:** <https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675>\
**Category:** Help\
**Tags:** yaml-selectors\
**Created:** [February 8, 2023, 4:12pm UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675 "2023-02-08T16:12:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AmbervanA](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AmbervanA](https://discourse.getdbt.com/u/AmbervanA)\
**Post date:** [February 8, 2023, 4:12pm UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675/1 "2023-02-08T16:12:51Z")

</div>

Hi,

I have created a model that I only want to run one time per month (lets say Model Month), but the other models need to run twice a day (lets say Model Day). I want to exclude the first model from the dbt run without using every time the --exclude function.

This is because we don’t want other colleagues to add the --exclude command to every dbt run. So we prefer to have a solution where we can run the ‘dbt run’ but without Model Month. Ones a month we would like to run the Model Month without changing any settings.

I tried to set the ‘enabled’ to false in the config and that works fine. But when I want to run Model Month, it says ‘The selection criterion ‘Model Month’ does not match any nodes’. This is because it is set to enabled false.

Is there an option to have by default Model Month disabled, but when I want it to run, I don’t need to change the settings from enabled false to true?

---

<div class="post-metadata">

**Author:** ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)\
**Post date:** [February 8, 2023, 11:24pm UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675/2 "2023-02-08T23:24:01Z")

</div>

Can you explain more about why you want to skip this most of the time? Your dbt project shouldn’t depend on nodes running an exact number of times – or on specific days – for it to be correct; it should be built in an [idempotent](https://docs.getdbt.com/terms/idempotent) manner.

Also keep in mind that when a node is disabled, it also can’t be `ref`’d by downstream models, so it would always have to be the final model in your DAG.

> [@AmbervanA](#):
>
> This is because we don’t want other colleagues to add the --exclude command to every dbt run. So we prefer to have a solution where we can run the ‘dbt run’ but without Model Month. Ones a month we would like to run the Model Month without changing any settings.

Your colleagues should be working in their own development environments, so this should only impact your production jobs which you should be able to set up once and then leave alone for the most part.

With all that said, you could use a YAML selector and set the [`default` property](https://docs.getdbt.com/reference/node-selection/yaml-selectors#default). This means that when you do a standard `dbt run` or `dbt build` without any other selection commands, it will exclude the monthly model. You would then have a separate job configured which is `dbt run --select monthly_only_model`.

```yaml
selectors:
  - name: everything_except_the_monthly
    description: "All nodes except the monthly one"
    default: true
    definition:
      union:
        - method: fqn
          value: "*"
        - exclude:
            - method: fqn
              value: monthly_only_model

```

---

<div class="post-metadata">

**Author:** ![AmbervanA](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AmbervanA](https://discourse.getdbt.com/u/AmbervanA)\
**Post date:** [February 9, 2023, 9:17am UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675/3 "2023-02-09T09:17:28Z")

</div>

Hi Joel,

Thanks for you reply!

We would like to skip this most of the time, because the data only needs to be refreshed ones per month. We don’t get new data in the intermediate period. In the model is a lot of complex sql code, so for the performance we would like to skip this file in the normal dbt run.

Thanks for the suggestion, I will try it asap.

---

<div class="post-metadata">

**Author:** ![AmbervanA](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AmbervanA](https://discourse.getdbt.com/u/AmbervanA)\
**Post date:** [February 9, 2023, 10:07am UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675/4 "2023-02-09T10:07:51Z")

</div>

I am not sure if the selectors can fix the problem, because you still have to call the command dbt run --selector everything\_except\_the\_monthly. I want to call the command dbt run and by default it excludes the monthly\_model instead of excluding the the model in the command. Is that possible?

---

<div class="post-metadata">

**Author:** ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)\
**Post date:** [February 9, 2023, 6:54pm UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675/5 "2023-02-09T18:54:00Z")

</div>

> [@AmbervanA](#):
>
> We don’t get new data in the intermediate period. In the model is a lot of complex sql code, so for the performance we would like to skip this file in the normal dbt run.

Have you considered an [incremental model](https://docs.getdbt.com/docs/build/incremental-models)? This is a perfect use case - you can put a check in for new data, something like

```sql
with upstream as (
  select * from {{ ref('upstream_complex_table') }}
)

select 
  -- complex transformations here... 
from upstream
{% if is_incremental() %}
  where upstream.loaded_at > (select max(this.loaded_at) from {{ this }} as this)
{% endif %}

```

> [@AmbervanA](#):
>
> I want to call the command dbt run and by default it excludes the monthly\_model instead of excluding the the model in the command. Is that possible?

It is possible, but you need to set the `default` property described above. When you do you’ll see this output:

```auto
$ dbt run
Running with dbt=1.4.1
[...]
Using default selector everything_except_the_monthly

```

---

<div class="post-metadata">

**Author:** ![nathan.calon](https://avatars.discourse-cdn.com/v4/letter/n/ba9def/32.png) [@nathan.calon](https://discourse.getdbt.com/u/nathan.calon)\
**Post date:** [February 10, 2023, 6:06pm UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675/6 "2023-02-10T18:06:27Z")

</div>

Would tags work?  
Tag everything with ‘monthly’, then tag everything excepting the ‘model month’ model with ‘daily’. then in the daily run, call tag:daily, and on the monthly run call tag:monthly

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [February 17, 2023, 6:06pm UTC](https://discourse.getdbt.com/t/exclude-model-from-dbt-run-by-default-but-still-want-to-run-the-model-separately/6675/7 "2023-02-17T18:06:50Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
