Looping a certain number of columns at a time

Hi there,

I have a table with 20 columns. I wonder if there is an easy way I could filter in columns two-by-two (not manually selecting all the time) via any loop node? For example, I need to loop first 2 columns (column 1&2) and do some manipulations with them, then loop next 2 columns (column 3&4), etc.

Or would transposing then chunk looping be the only way?

Thank you,
Odko

Hi,
Maybe you can use Extract Column Header and a chunk loop to achieve what you want? You will still have all columns in your loop, but the current columns can be made available as flow variables.
Kind regards,
Alexander

1 Like

Hi,

You have to select two columns an then filter that two columns. For the first task @AlexanderFillbrunn gives you the solution for the second part, how to filter columns you can see some solutions here: Select first n columns of a table

Kind regards,
Andrej

2 Likes

Hi @Odko

I think you need a Transpose node and a Chunck Loop. At least I needed both to create a solution. See this workflow looping_a_certain_number_ of_columns.knwf (29.7 KB) . You can adjust the number of columns you want to some calculation on by modifying the Chunk Loop setting and adding another row to the Table Creater node.

.
gr. Hans

4 Likes

Hi there @Odko,

can you tell us more about your use case? What are you doing with columns in loop? Also is number of columns fixed and are columns names same?

Br,
Ivan

1 Like

Dear @AlexanderFillbrunn, @andrejz, @HansS, @ipazin, thank you so much for your kind and timely suggestions.

I followed the way I was first talking, i.e. transposing and chunk looping, as the task was quite urgent. It worked for me. Here is the workflow:

I needed to filter in every 2 columns (as a pair) in a non-repetitive way (i.e. if I selected first two columns, then they are not selected in next iterations) and multiply them and get a value.

Kind regards,
Odko

3 Likes

Hi @Odko,

glad you made it :wink:

Br,
Ivan

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