# Use Variables in Ephemeral Models

**URL:** <https://discourse.getdbt.com/t/use-variables-in-ephemeral-models/17162>\
**Category:** Help\
**Tags:** variables, ephemeral-models\
**Created:** [November 29, 2024, 12:20pm UTC](https://discourse.getdbt.com/t/use-variables-in-ephemeral-models/17162 "2024-11-29T12:20:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eve](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@Eve](https://discourse.getdbt.com/u/Eve)\
**Post date:** [November 29, 2024, 12:20pm UTC](https://discourse.getdbt.com/t/use-variables-in-ephemeral-models/17162/1 "2024-11-29T12:20:33Z")

</div>

Hi,

I have two Redshift models model1 and model2 that reuse the same CTE except for one filter, so

Model1.sql  
With example\_cte as (select \* from mydata where column1 = 1 and filter2 and filter3 qualify row\_number() over (partition by col1, col2 order by col1) = 1),  
select \* from table2 left join example\_cte on example\_cte.foreign\_key = table2.id

Model2.sql  
With example\_cte as (select \* from mydata where column1 = 2 and filter2 and filter3 qualify row\_number() over (partition by col1, col2 order by col1) = 1),  
select \* from table2 left join example\_cte on example\_cte.foreign\_key = table2.id

I now created an ephemeral model for the CTE in order to avoid duplicating logic but can’t figure out a way to set the filter on column1 dynamically inside the model files of model1 and model2.

Is there a way to do that?

Thank you!

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [November 30, 2024, 8:12am UTC](https://discourse.getdbt.com/t/use-variables-in-ephemeral-models/17162/2 "2024-11-30T08:12:42Z")

</div>

Note: `@Nick Pinfold` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1732954355256939?thread_ts=1732882858.436269&cid=CBSQTAPLG). It might not have transferred perfectly.
