# Using flow variables to set GroupBy grouping columns

**URL:** <https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766>\
**Category:** KNIME Analytics Platform\
**Created:** [May 11, 2017, 4:35pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766 "2017-05-11T16:35:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sslattery](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/8dc957/32.png) [@sslattery](https://forum.knime.com/u/sslattery)\
**Post date:** [May 11, 2017, 4:35pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/1 "2017-05-11T16:35:05Z")

</div>

I would like to be able to store a list of column names as flow variables (either a single list flow variable, or multiple single value flow variables), and then use those column names for grouping in downstream "GroupBy" nodes. &nbsp;I would like the setup to be able to handle&nbsp;a variable number of grouping column names. I cannot figure out how to set up the flow variables in the GroupBy node to achieve this. &nbsp;Any suggestions would be welcome.

---

<div class="post-metadata">

**Author:** ![Iris](https://forum-cdn.knime.com/user_avatar/forum.knime.com/iris/32/14_2.png) [@Iris](https://forum.knime.com/u/Iris)\
**Post date:** [May 17, 2017, 6:51pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/2 "2017-05-17T18:51:53Z")

</div>

Hi,

you need to preconfigure the groupby node for being able to do this. only after the first configuration you can define the flow variables.

You than can use pattern based aggregation page and add a predefined number of rows. Each row can than be controlled from the outside via flow variables.

As it is a regex, you can also construct a regex which will match multiple columns at once.

i hope this helps to get you started!

Cheers, Iris&nbsp;

---

<div class="post-metadata">

**Author:** ![sslattery](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/s/8dc957/32.png) [@sslattery](https://forum.knime.com/u/sslattery)\
**Post date:** [July 19, 2017, 10:15pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/3 "2017-07-19T22:15:04Z")

</div>

Thanks, I'll give it a try.

---

<div class="post-metadata">

**Author:** ![lcollia](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/f07891/32.png) [@lcollia](https://forum.knime.com/u/lcollia)\
**Post date:** [April 29, 2020, 12:16pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/4 "2020-04-29T12:16:32Z")

</div>

Hi @Iris,

I come back to this thread as its related.

I have a configuration node/widget in which the user can select multiple columns (the number of columns can go from 1 to 5 for expl). I want to group on these columns in the GroupBy node.  
If as preconfigure the node with 5 columns (as you propose), I can find a way with flowvariables to preselect the columns for the grouping. But I will have problems when the user will select different columns and/or less for the grouping.  
In brief, I would like to use an array of columns name for the grouping or to indicate a regex of the name of the columns that I want to group.

Any suggestion?  
Thanks in advance, Lionel

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [April 29, 2020, 3:33pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/5 "2020-04-29T15:33:49Z")

</div>

Hi there @lcollia,

see this [topic](https://forum.knime.com/t/how-to-apply-different-column-combinations-1-column-in-group-by-node-by-flow-variables/21120).

There you will find workflow example how to control variable number of columns in GroupBy node using flow variable type array/collection which is new from version 4.1. Probably you’ll need to modify wf example to your use case.

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![lcollia](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/f07891/32.png) [@lcollia](https://forum.knime.com/u/lcollia)\
**Post date:** [April 29, 2020, 8:19pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/6 "2020-04-29T20:19:19Z")

</div>

Hi Ivan,

Thank you for your answer. I will have a look at your solution that is very interesting.

In the meantime I found an other solution that is to filter and conserve the columns on which you want to do the group by, then to merge then in 1 column (a list for expl) [you can do that because the column merger allow to merge all available columns by the regex]  
This unique column will have the same name in all situation, so you can use this merged column for the group by. With a column appender somewhere to keep your original data, the work is done!

Best,  
Lionel

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [April 30, 2020, 4:06pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/7 "2020-04-30T16:06:20Z")

</div>

Hi Lionel!

Glad you found a way. And it is and interesting one 🙂

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 23, 2023, 8:26pm UTC](https://forum.knime.com/t/using-flow-variables-to-set-groupby-grouping-columns/8766/8 "2023-06-23T20:26:37Z")

</div>


