# \#macro

**URL:** https://discourse.getdbt.com/tag/macro/86.md

[Latest](https://discourse.getdbt.com/latest.md) · [Categories](https://discourse.getdbt.com/categories.md) · [Tags](https://discourse.getdbt.com/tags.md)

---

## [Rendering Macro within Macro](https://discourse.getdbt.com/t/rendering-macro-within-macro/20001)

<div class="topic-metadata">

**Author:** [@Priest](https://discourse.getdbt.com/u/Priest)\
**Replies:** 0\
**Last updated:** [July 31, 2025, 12:41pm UTC](https://discourse.getdbt.com/t/rendering-macro-within-macro/20001 "2025-07-31T12:41:30Z")

</div>

The problem I’m having Hi, I’m trying to dynamically build the columns in the “SELECT” query utilizing a customer macro and the model’s YML file. And I’m getting ‘macro’ undefined error. The context of why I’m trying…

---

## [macro for create date interval](https://discourse.getdbt.com/t/macro-for-create-date-interval/15151)

<div class="topic-metadata">

**Author:** [@Milica\_Savic](https://discourse.getdbt.com/u/Milica_Savic)\
**Replies:** 1\
**Last updated:** [August 26, 2024, 5:45pm UTC](https://discourse.getdbt.com/t/macro-for-create-date-interval/15151 "2024-08-26T17:45:23Z")

</div>

I have wrote macro ‘{% macro get\_two\_quarters\_ago\_end() %} dateadd(day, - 1, dateadd(‘QUARTER’, - 1, date\_trunc(‘QUARTER’, current\_date()))) {% endmacro %}’ to calculate dynamic date from two quoters form current quatr…

---

## [Can I generate yml files to the target folder in macro](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104)

<div class="topic-metadata">

**Author:** [@jeeplvnz](https://discourse.getdbt.com/u/jeeplvnz)\
**Replies:** 8\
**Last updated:** [May 13, 2024, 3:48pm UTC](https://discourse.getdbt.com/t/can-i-generate-yml-files-to-the-target-folder-in-macro/9104 "2024-05-13T15:48:54Z")

</div>

The problem I’m having I want to generate yml files to the target folder in macro. Is that possible? Thank you.

---

## [Can I call a python function inside the macro written in jinja?](https://discourse.getdbt.com/t/can-i-call-a-python-function-inside-the-macro-written-in-jinja/11989)

<div class="topic-metadata">

**Author:** [@pradeep244](https://discourse.getdbt.com/u/pradeep244)\
**Replies:** 3\
**Last updated:** [February 12, 2024, 8:16am UTC](https://discourse.getdbt.com/t/can-i-call-a-python-function-inside-the-macro-written-in-jinja/11989 "2024-02-12T08:16:13Z")

</div>

I have a column which contains a json string. using run\_query() , I captured the json string into a variable inside a macro written in jinja sql. I want to write a python function and call the function inside th…

---

## [Using a macro argument in a post\_hook](https://discourse.getdbt.com/t/using-a-macro-argument-in-a-post-hook/11822)

<div class="topic-metadata">

**Author:** [@alexb](https://discourse.getdbt.com/u/alexb)\
**Replies:** 0\
**Last updated:** [January 30, 2024, 5:36pm UTC](https://discourse.getdbt.com/t/using-a-macro-argument-in-a-post-hook/11822 "2024-01-30T17:36:00Z")

</div>

Hi there! I’m trying to run a macro using dynamic argument and then use this argument in a post\_hook to that same process, and insert the argument into a different table. Something like this: –my\_macro.sql {% macro ab…

---

## [How to call a model from a macro](https://discourse.getdbt.com/t/how-to-call-a-model-from-a-macro/9140)

<div class="topic-metadata">

**Author:** [@janbenisek](https://discourse.getdbt.com/u/janbenisek)\
**Replies:** 4\
**Last updated:** [January 18, 2024, 8:43am UTC](https://discourse.getdbt.com/t/how-to-call-a-model-from-a-macro/9140 "2024-01-18T08:43:09Z")

</div>

The problem I’m having I’d like to execute a particular model in a macro. Something along this way: {%- macro foobar(model\_name, target\_name) -%} dbt run -s {{ model\_name }} -t {{ target\_name }} {%- endmacro -%} The …

---

## [dbt - snowflake - validate function](https://discourse.getdbt.com/t/dbt-snowflake-validate-function/9617)

<div class="topic-metadata">

**Author:** [@roberbonox](https://discourse.getdbt.com/u/roberbonox)\
**Replies:** 0\
**Last updated:** [August 19, 2023, 1:02am UTC](https://discourse.getdbt.com/t/dbt-snowflake-validate-function/9617 "2023-08-19T01:02:12Z")

</div>

The problem i have is that i call from a model a macro with parameter as a post\_hook . I’m doing this because i have ingestions as COPY INTO in snowflake with on\_error = continue condition and i want to retrieve all the…

---

## [Snowpipe with dbt](https://discourse.getdbt.com/t/snowpipe-with-dbt/9583)

<div class="topic-metadata">

**Author:** [@roberbonox](https://discourse.getdbt.com/u/roberbonox)\
**Replies:** 0\
**Last updated:** [August 16, 2023, 8:25pm UTC](https://discourse.getdbt.com/t/snowpipe-with-dbt/9583 "2023-08-16T20:25:21Z")

</div>

Hi, in my company we already have a pipeline developed in snowflake in which through external stages and snowpipe se load daily objects (csv files) from and S3 bucket to a table. After that, a process through streams, t…

---

## [How to access meta from macro](https://discourse.getdbt.com/t/how-to-access-meta-from-macro/8698)

<div class="topic-metadata">

**Author:** [@Process](https://discourse.getdbt.com/u/Process)\
**Replies:** 3\
**Last updated:** [June 15, 2023, 8:35am UTC](https://discourse.getdbt.com/t/how-to-access-meta-from-macro/8698 "2023-06-15T08:35:23Z")

</div>

I have below in schema.yml models: - name: my\_model meta: foo: 1234 How to get the foo value from macro? Ideally I expect the macro has this , and from this I can get the foo value.

---

## [Is there a way to select models that depend on specific macro?](https://discourse.getdbt.com/t/is-there-a-way-to-select-models-that-depend-on-specific-macro/8217)

<div class="topic-metadata">

**Author:** [@artem.popov](https://discourse.getdbt.com/u/artem.popov)\
**Replies:** 3\
**Last updated:** [May 12, 2023, 2:05pm UTC](https://discourse.getdbt.com/t/is-there-a-way-to-select-models-that-depend-on-specific-macro/8217 "2023-05-12T14:05:31Z")

</div>

The problem I’m having I changed a macro and want to update (run) all models that depend on the macro. Is there a way to do so? What I’ve already tried Usually, I check the models that depend on the macro in the code an…

---

## [how to pass variable and string to macro?](https://discourse.getdbt.com/t/how-to-pass-variable-and-string-to-macro/5475)

<div class="topic-metadata">

**Author:** [@hurcy](https://discourse.getdbt.com/u/hurcy)\
**Replies:** 1\
**Last updated:** [December 6, 2022, 7:54am UTC](https://discourse.getdbt.com/t/how-to-pass-variable-and-string-to-macro/5475 "2022-12-06T07:54:06Z")

</div>

Hi, I would like to use macro returning values depending on parameter like this. macros/fn\_get\_bar.sql {% macro fn\_get\_bar(foo) %} {% if foo== 1 %} {{return ('aaa')}} {% else %} ... {% endif %} {%- endmacro %} I…

---

## [getting metadata at runtime in macro](https://discourse.getdbt.com/t/getting-metadata-at-runtime-in-macro/5447)

<div class="topic-metadata">

**Author:** [@obar1](https://discourse.getdbt.com/u/obar1)\
**Replies:** 2\
**Last updated:** [December 1, 2022, 2:10am UTC](https://discourse.getdbt.com/t/getting-metadata-at-runtime-in-macro/5447 "2022-12-01T02:10:48Z")

</div>

Hello ppl - I have this case model1 {{ config(materialized="table", schema="clean") }} model2 {{ config(materialized="table", schema="stg") }} then {%- macro round\_percentage(col) -%} ROUND( {{ col }},3) {%- en…
