# Create n columns

**URL:** <https://forum.knime.com/t/create-n-columns/40079>\
**Category:** KNIME Analytics Platform\
**Tags:** java-snippet\
**Created:** [February 21, 2022, 9:38pm UTC](https://forum.knime.com/t/create-n-columns/40079 "2022-02-21T21:38:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuisMP](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/b19c9b/32.png) [@LuisMP](https://forum.knime.com/u/LuisMP)\
**Post date:** [February 21, 2022, 9:38pm UTC](https://forum.knime.com/t/create-n-columns/40079/1 "2022-02-21T21:38:14Z")

</div>

Hi,

I have a column with 5 rows, something like this:

Col1  
1  
2  
3  
4  
5

and I want to create 12 columns with the exact same data as my first column. The number of columns would be decreasing once a month. What I want is to be able to select how many columns I want to be created, wether is manual configuring the node/script or user input.

Any ideas how to do this?

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [February 21, 2022, 10:43pm UTC](https://forum.knime.com/t/create-n-columns/40079/2 "2022-02-21T22:43:20Z")

</div>

Hi @LuisMP and welcome to the Knime Community.

This can easily be done with a Counting Loop since you know how many columns you want, and you can close the loop with a Loop End (Column Append) since you want to append the results as columns. Add a Variable Creator to define your number of columns (n).

Something as simple as this will do the job:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/a/1a758514ced8b2374a006b3cad63034872a3d63a.png)

I used a variable called “num\_of\_col” to define “n”, and I set it to 12:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/7/4/74a368a287afae350b7df81cf52b8d723f39bed6.png)

And I use this variable in the Counting Loop Start to define how many iterations I want:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/a/3/a388fcd8f2467aa5bc95fc39aa24650eb6f906f5.png)

This is my starting table:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/3/332e6285015893154eec924489a7d5679cb3c9f2.png)

Results:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/1/9118934ec033deb19998af2c0c8085edf7a672b3.png)

Of course, if your table have other tables that you do not want to duplicate, there will be additional manipulations to be done.

And you can also easily rename the columns using Column Rename (Regex) since they have patterns in their current name.

Here’s the workflow: [Duplicate n columns.knwf](https://forum.knime.com/uploads/short-url/bEiV7qmh29cB1ef96XCZWDtCxmp.knwf) (11.5 KB)

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [February 22, 2022, 5:29pm UTC](https://forum.knime.com/t/create-n-columns/40079/3 "2022-02-22T17:29:19Z")

</div>

Another way could be transposing the data

 ![save](https://forum-cdn.knime.com/uploads/default/original/3X/0/0/00fb95d2e2e359574f6cf6563b751c8489d1e0e1.png)

I once heared transpose is not the fastest node so it might depend on your data size but I thought sharing doesn’t help  
Additional potential renaming steps as @bruno29a kindly already pointed out.  
br

---

<div class="post-metadata">

**Author:** ![LuisMP](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/l/b19c9b/32.png) [@LuisMP](https://forum.knime.com/u/LuisMP)\
**Post date:** [February 23, 2022, 12:03am UTC](https://forum.knime.com/t/create-n-columns/40079/4 "2022-02-23T00:03:14Z")

</div>

Thank you so much! this really made the work easier for me

---

<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:** [May 24, 2022, 12:03am UTC](https://forum.knime.com/t/create-n-columns/40079/5 "2022-05-24T00:03:59Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
