Getting data of a certain column

Hi,

I want to copy the value of a certain column to a new column depending on a value in that row. E. g. a table looks like this:
col2 col3 col4 col5 selector appendedCol
1 2 3 4 2 2
5 3 4 1 1 5
1 2 3 4 4 4
1 2 3 4 6 0

Note that the appededCol shall be 0 if the selector is too great. The number of col(x) may also vary, but if things are unsolvable we could assume it is fix. I played around with “Column List Loop Start” but there is no index. A not convenient solution may be to concatenate 4 Math Formula filters which looks like this:
$$CURRENT_COLUMN$$ * (x == $selector$) and fix the x to 1, 2, 3, 4 respectively. Saying this I have at least 24 columns to select from and this could be a cumbersome work. Any better ideas?

Hi there!

Maybe there is an easy solution with only using one node. So use Column Expressions node with following expression:

column(column(“selector”)-1)

In this node with function column(x) you are approaching the x-st column. So in each row you will take value from column based on value from selector. As is your logic. You need to subtract 1 because column count starts from 0 :wink: Column Expression node is available from 3.6 version and needs to be installed from Extensions. After this you will have missing where selector is too big so use Missing Value node to replace it with 0. Almost one node :smiley:

Regarding Column List Loop Start there is index (if we are on the same page) but as a flow variable called currentIteration :wink:

If you will have problems I can share workflow.

Br,
Ivan

4 Likes

Worked like a charm. Thanks for that cool solution.

1 Like