# CASE: dynamic variable names

**URL:** <https://community.silverfin.com/t/case-dynamic-variable-names/1198>\
**Category:** Cases\
**Tags:** variables, use\_case\
**Created:** [September 17, 2018, 11:53am UTC](https://community.silverfin.com/t/case-dynamic-variable-names/1198 "2018-09-17T11:53:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [September 17, 2018, 11:53am UTC](https://community.silverfin.com/t/case-dynamic-variable-names/1198/1 "2018-09-17T11:53:00Z")

</div>

To explain why we use dynamic variable names in this case:

> [@CASE: create fori and group on certain values](https://community.silverfin.com/t/case-create-fori-and-group-on-certain-values/1195):
>
> Let’s say we import a whole bunch of data through the automatic reconciliation function in a reconciliation template. To make it simple, I’ll import all parts of a car with their expenses from a certain excel-sheet I’ve gotten from my client, like this: [03] Because of all double types in the excel-sheet, I’d like to group these on type to see what amount correspond with what type. I’ll even try to make type Wheels (with capital) and wheels (without capital) the same type. To get something li…

Let’s say we create a variable called :

```auto
{% assign var_xyz = "100" %}

```

We also create this:

```auto
{% assign i = "xyz" %}
{% capture variable %}var_{{ i }}{% endcapture %} 

```

So the output of `{{ variable }}` is simply the name we capture :

> var\_xyz

However, if we want to access the value of the variable `var_xyz`, we need to use this:

```auto
{{ [variable] }} 

```

which outputs this:

> 100

So the name of the variable `var_xyz` gets created by the capture-code, and we display that value with .

A case where this is used, can be found here:

> [@CASE: create fori and group on certain values](https://community.silverfin.com/t/case-create-fori-and-group-on-certain-values/1195):
>
> Let’s say we import a whole bunch of data through the automatic reconciliation function in a reconciliation template. To make it simple, I’ll import all parts of a car with their expenses from a certain excel-sheet I’ve gotten from my client, like this: [03] Because of all double types in the excel-sheet, I’d like to group these on type to see what amount correspond with what type. I’ll even try to make type Wheels (with capital) and wheels (without capital) the same type. To get something li…

Complete code use case:

```auto
{% assign var_xyz = "100" %}
{% assign i = "xyz" %}
{% capture variable %}var_{{ i }}{% endcapture %}

{% comment %}Output of the capture code{% endcomment %}  
{{ variable }}

{% comment %}Output of the variable assign code{% endcomment %} 
{{ [variable] }} 

```
