# Creating dynamic dimension with query parameters

**URL:** <https://community.holistics.io/t/creating-dynamic-dimension-with-query-parameters/1978>\
**Category:** Tips and Showcases\
**Created:** [June 28, 2024, 5:22am UTC](https://community.holistics.io/t/creating-dynamic-dimension-with-query-parameters/1978 "2024-06-28T05:22:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanh](https://community.holistics.io/user_avatar/community.holistics.io/thanh/32/53_2.png) [@thanh](https://community.holistics.io/u/thanh)\
**Post date:** [June 28, 2024, 5:22am UTC](https://community.holistics.io/t/creating-dynamic-dimension-with-query-parameters/1978/1 "2024-06-28T05:22:14Z")

</div>

Assuming that you have a model `model_with_2_dims` with 2 dimensions: `dim1` and `dim2`. You want your users to be able choose an option from a few selected values, then dynamically select `dim1` or `dim2` based on that input during runtime.

```auto
Model model_with_2_dims {
  dimension dim1 { ... }
  dimension dim2 { ... }
}

```

You can do that with the code below:

```auto
Model model_with_dynamic_dim {
  type: 'query'
  label: 'Model with dynamic dim'
  description: ''
  data_source_name: 'my_ds'
  owner: 'my_email'

  param dimension_choice {
      label: 'Selected Dimension'
      type: 'text'
      allowed_values: ["choice1", "choice2"]
  }

  dimension dynamic_dimension {
    label: 'Dynamic Dimension'
    type: 'text'
    hidden: false
    definition: @sql {{ #SOURCE.dynamic_dimension }};;
  }

  query: @sql
    select CASE
        WHEN {% filter(dimension_choice) %} 'choice1' {% end %} THEN dim1
        WHEN {% filter(dimension_choice) %} 'choice2' {% end %} THEN dim2
        ELSE 'unknown'
    END as dynamic_dimension
    from {{ #model_with_2_dims }}
  ;;
}

```

The full documentation for this can be found [here](https://docs.holistics.io/as-code/query-parameters#how-to-set-up-dynamic-dimension-with-parameters).

Cheers!

---

<div class="post-metadata">

**Author:** ![gwizard](https://community.holistics.io/user_avatar/community.holistics.io/gwizard/32/1761_2.png) [@gwizard](https://community.holistics.io/u/gwizard)\
**Post date:** [September 21, 2024, 6:54pm UTC](https://community.holistics.io/t/creating-dynamic-dimension-with-query-parameters/1978/2 "2024-09-21T18:54:40Z")

</div>

Does this same logic work for choosing between measures?

---

<div class="post-metadata">

**Author:** ![dat.cv](https://community.holistics.io/user_avatar/community.holistics.io/dat.cv/32/876_2.png) [@dat.cv](https://community.holistics.io/u/dat.cv)\
**Post date:** [September 23, 2024, 2:34am UTC](https://community.holistics.io/t/creating-dynamic-dimension-with-query-parameters/1978/3 "2024-09-23T02:34:13Z")

</div>

Yes, this logic is applicable for measures as well.
