Swapping values inside a table

Hi,

I would like to know, if there is an easy way to swap values (see below).

The goal should looks like this

I could achieve that by using the JavaSnippet, but it is not very smart:

switch(ROWINDEX){
case 0:
out_2019 = getCell(ROWINDEX+8, tInt);
out_2018 = getCell(ROWINDEX+7, tInt);
out_2017 = getCell(ROWINDEX+6, tInt);
out_2016 = getCell(ROWINDEX+5, tInt);
out_2015 = getCell(ROWINDEX+4, tInt);
out_2014 = getCell(ROWINDEX+3, tInt);
out_2013 = getCell(ROWINDEX+2, tInt);
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 1:
out_2018 = getCell(ROWINDEX+7, tInt);
out_2017 = getCell(ROWINDEX+6, tInt);
out_2016 = getCell(ROWINDEX+5, tInt);
out_2015 = getCell(ROWINDEX+4, tInt);
out_2014 = getCell(ROWINDEX+3, tInt);
out_2013 = getCell(ROWINDEX+2, tInt);
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 2:
out_2017 = getCell(ROWINDEX+6, tInt);
out_2016 = getCell(ROWINDEX+5, tInt);
out_2015 = getCell(ROWINDEX+4, tInt);
out_2014 = getCell(ROWINDEX+3, tInt);
out_2013 = getCell(ROWINDEX+2, tInt);
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 3:
out_2016 = getCell(ROWINDEX+5, tInt);
out_2015 = getCell(ROWINDEX+4, tInt);
out_2014 = getCell(ROWINDEX+3, tInt);
out_2013 = getCell(ROWINDEX+2, tInt);
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 4:
out_2015 = getCell(ROWINDEX+4, tInt);
out_2014 = getCell(ROWINDEX+3, tInt);
out_2013 = getCell(ROWINDEX+2, tInt);
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 5:
out_2014 = getCell(ROWINDEX+3, tInt);
out_2013 = getCell(ROWINDEX+2, tInt);
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 6:
out_2013 = getCell(ROWINDEX+2, tInt);
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 7:
out_2012 = getCell(ROWINDEX+1, tInt);
out_2011 = getCell(ROWINDEX, tInt);
break;
case 8:
out_2011 = getCell(ROWINDEX, tInt);
break;
}

What I basically miss, a list of all values inside that row.
Maybe anyone of you have an idea, how to solve that.

Thank you and looking forward hearing from you :slight_smile:

Best,
John

It looks as transpose


and

nodes could help you.

Thanks for your reply.

Actually, I did that. But when I do that, I won’t get my resulted table.

The column “2011” should contain all “92” values.

Hi @just-n-guy-en-charge!

Welcome to KNIME community!

If I got it right you use Lag Column node to get data in format from your first print screen. In my opinion I would skip that part and using only first column create others with workflow like this:

Basically loop over each row and using Constant value Column and Column Expressions nodes create one column in each iteration. There is a lot of flow variables in this workflow so you want to check how they work if haven’t yet.

There might be an easier solution but in any case afraid you can not avoid some code writing.

Workflow is attached. If any questions feel free to ask.

2019_03_28_Lower_Triangular_Matrix.knwf (27.7 KB)

Br,
Ivan