Pivoting Arrays


#1

Is there a simple way to pivot an array? If my array looks something like this.
Qty;Cost;MU;Price
100;24;.10;30
200;30;.15;45
300;40;.30;50
etc…etc

I want to pivot it to look like this

100;200;300
24;30;40
.10;.15;.30
30;45;50


#2

You could use the looparray statement to do the work. Here is my test code I used to produce your desired results:

local x,z
z=""
x="100;24;.10;30
200;30;.15;45
300;40;.30;50"
looparray array(x,1,¶),";",element,index
    z=arraystrip(z+¶+replace(arraycolumn(x,index,¶,";"),¶,";"),¶)
endloop
message z

This basically steps through the first line of the original array one column at a time and gathers all the items of that column replacing the returns with semicolons for the new array. It takes the current value of the new array and adds a return and then the current column elements as noted above. Finally it strips any empty elements from the new array.