Reshape Function
Reshape
Reshape returns an array of desired size produced by arranging the values of the Input array. The illustrations is given below for ReshapeRows.
ReshapeRows
For the output array, rows are accessed top to bottom. Within each row, values are accessed left to right.
Sample Data
We will consider the following sample data and will arrange the values using reshape.
Step 1:
Click on More from Sheetkraft tab and select Reshape.
Step 2
Select the range you want to reshape.
Step 3
In Results, we can specify the dimensions of the output array in number of rows or columns. At least either rows or column values need to be provided.
Result:
Rows: number of rows in output range
Columns: number of columns in output range
Arrange values by:
Selecting Rows will implement ReshapeRows and columns will implement ReshapeColumns.
If size of result is greater than size of the source:
Cycle through the values in the source will read the start with the first value in the source array to be repeated after the source values, or select Use a constant value and the value provided will be repeated.
Result
We can see that the values in the output range are arranged by rows from the source range and the function ReshapeRows.sk is used.
ReshapeColumns
For the output array, columns are accessed left to right. Within each column, values are accessed top to bottom.
Sample
We consider the same sample data. Here, we want to arrange the Interest for each Company in columns.
Step 1
We select column D values in the Source.
Step 2
As we know we want 3 columns in the result, we will provide Columns as 3 and as we want to read the values top to bottom in columns from source, we will select Columns.
Step 3
The values are arranged as per columns in the result and the function is ReshapeColumns.sk
Some Examples:
1) Both Rows and Columns are given
Let’s say we want to arrange the Amount values of only the first 2 Companies in columns.
As we know the number of rows and columns we want in our result array, we provide Rows as 5 and columns as 2.
2) Constant Values
Let us take the below sample data where we have to fill the Payment Mode in column G with the values from Column B. The additional rows in New Transaction ID will have Payment Mode as UPI.
In Reshape, provide Rows as countdown.sk of the F2 and columns as 1. We will select Use a constant value and provide the value “UPI”.
3) Reshape a constant value
In the below example, we want to fill the category column in the table with the value in cell B2.
We select the DataRange as cell B2 and provide rows and columns as shown below.