# Dynamic column name in expression builder

**URL:** <https://community.qfield.org/t/dynamic-column-name-in-expression-builder/490>\
**Category:** Ask the Community\
**Tags:** gh-import\
**Created:** [14 May 2025 02:26 UTC](https://community.qfield.org/t/dynamic-column-name-in-expression-builder/490 "2025-05-14T02:26:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 02:26 UTC](https://community.qfield.org/t/dynamic-column-name-in-expression-builder/490/1 "2025-05-14T02:26:24Z")

</div>

Hi everyone,

I need some help to figure out how to insert a variable column name in an expression, and that expression to RETURN as expected.  
My case:  
with attribute(‘rt\_id’) = ‘UCM000010’ – I obtain an unique ID value stored in column “rt\_id” for any current\_feature within main.table  
lv.table contain 1 column for each feature from main.table, with name as feature.rt\_id to which is referring to.  
I try to retrieve information from dedicated column(along others) within lv.table for each feature within main.table.  
If I write the expression as:

### aggregate(

```
layer := 'lv',
aggregate := 'concatenate',
expression := concat("code", ' - ', "UCM000010", ' ', "um"),
filter := "UCM000010" IS NOT NULL
concatenator := '\n'

```

)  
I have the correct RETURN as:  
‘10010640 - 1 stk  
10010413 - 10.99 lfm  
10028103 - 10.99 lfm’

When I try to insert that “column\_name” dynamic as:

### aggregate(

```
layer := 'lv',
aggregate := 'concatenate',
expression := concat("code", ' - ', attribute('rt_id'), ' ', "um"),
concatenator := '\n'

```

)  
expression don’t identify what column\_name was referring to, RETURN only “code” & “um”, but for ALL rows & not values from specific column(with “filter” excluded because the RETURN was empty IF no column identified correctly):  
'10010640 - stk  
10010713 - stk  
10010776 - lfm  
…  
So, clearly, expression don’t take that feature.rt\_id correct in consideration and RETURN without information from that column within lv.table. I try also with “current\_feature” OR “current\_value”, same wrong result.  
How should I pass correctly that feature attribute as column name in builder expression as the RETURN to be as expected?  
Thank you in advance for your time and help!

* * *

_Imported from [GitHub discussion](https://github.com/opengisch/qfield/discussions/5191) by @NeaCri on 2024-04-17T07:23:01Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 02:26 UTC](https://community.qfield.org/t/dynamic-column-name-in-expression-builder/490/2 "2025-05-14T02:26:25Z")

</div>

1. Does this work in QGis ? If not, it’s not a QField issue
2. As I understand (maybe bad), you’re referring to 2 tables. In your expression, where is the table reference ? Have you set a relation between tables ? By setting a relation (joining), you could make appear your 2nd table’s attribute in your first one and be able to make your expression work…

* * *

_Imported from [GitHub comment](https://github.com/opengisch/QField/discussions/5191#discussioncomment-9144949) by @VxTedxV on 2024-04-17T15:50:17Z_

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex018/uploads/qfield/original/1X/7d3726da0ef5099a1e135505c03d2f125d527aae.png) [@system](https://community.qfield.org/u/system)\
**Post date:** [14 May 2025 02:26 UTC](https://community.qfield.org/t/dynamic-column-name-in-expression-builder/490/3 "2025-05-14T02:26:27Z")

</div>

1. Yes, in qGIS I try to create a virtual column(or create new field and set DEFAULT value), on each of 5 main.spatial.tables) where to spell out those existing information from a separate non-spatial.lv.table(which contain 1 column for each feature within main.tables) within the project layers.
2. I do not have JOIN those tables until now and I dont think this is the solution because the “Joined field” is different for each feature within main.tables(in lv. table are around 800 columns) and is no other connection between tables on fields like “id” or “code”, except…

The lv.table is created in PostgreSQL combining an existing(services).table (which contain around 200 unique “code” rows) with dynamic\_columns for all features(unique rt\_id.column\_name), so, the only connection between lv.table AND any of main.table is that feature.rt\_id from main.table which is a column\_name within lv.table. Then, if I cannot pass that feature.rt\_id in aggregate, is not any other way to connect those tables and retrieve aimed information with JOIN or Relation.  
I try to avoid to write this simple logic in server-side, PostgreSQL, aiming only for a virtual column for each layer in front-end(qGIS) with that “aggregate” formula based on each feature.rt\_id, but if I don’t find a solution on this issue, probably it will be next step.  
more testing(new field):  
With: expression := concat(“code”, ’ - ', “qty”, ’ ', “um”) I retrieve ‘qty’ column which is sum of all 800 other columns, no errors.  
I need to change that “qty” with specific column\_name = feature.rt\_id(on DEFAULT for new field), I retrieve just an empty list with attribute(‘rt\_id’). If I write attribute(‘rt\_id’) in DEFAULT for new field, I retrieve as expected, the feature.rt\_id.  
But within the expression in aggregate formula is not recognized as a column\_name from interrogated table.

I will want to thank you for your attempt!

* * *

_Imported from [GitHub comment](https://github.com/opengisch/QField/discussions/5191#discussioncomment-9147717) by @NeaCri on 2024-04-17T21:01:12Z_
