# Custom target Dataset creation in GBQ using DBT.

**URL:** <https://discourse.getdbt.com/t/custom-target-dataset-creation-in-gbq-using-dbt/10847>\
**Category:** Help\
**Tags:** bigquery, dbt-cloud, macros, dbt-core\
**Created:** [November 17, 2023, 7:42am UTC](https://discourse.getdbt.com/t/custom-target-dataset-creation-in-gbq-using-dbt/10847 "2023-11-17T07:42:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siddharth](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@Siddharth](https://discourse.getdbt.com/u/Siddharth)\
**Post date:** [November 17, 2023, 7:42am UTC](https://discourse.getdbt.com/t/custom-target-dataset-creation-in-gbq-using-dbt/10847/1 "2023-11-17T07:42:34Z")

</div>

## The problem I’m having

We have 3 environments, i.e., Landing, Staging, and Data Mart. Tables from different sources will be loaded in the Landing dataset, and we have a view in the same(Landing) layer to get the incremental data as source and table in the Staging dataset as target. Again, View in the Staging layer is used as source and DIM/FACT tables as target in the Data Mart Dataset.

However, when we give the location of the target schema in the STAGING model, it creates the table in the default schema that we provided in the Credentials.

## The context of why I’m trying to do this

The requirement mentioned above is working with Snowflake, but we have to migrate to the GBQ.

## What I’ve already tried

We followed the steps mentioned in the link below:

> **[Custom schemas | dbt Developer Hub](https://docs.getdbt.com/docs/build/custom-schemas#an-alternative-pattern-for-generating-schema-names)**
>
> Configure custom schemas for your dbt model's tables and views in the database.

## Some example code or error messages

```auto
{% macro generate_schema_name_for_env(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if target.name == 'DBT_PROD' and custom_schema_name is not none -%}

        {{ custom_schema_name | trim }}

    {%- else -%}

        {{ default_schema }}

    {%- endif -%}

{%- endmacro %}

```
