Forum Discussion

Melvin_Khoo's avatar
Melvin_Khoo
Copper Contributor
Dec 03, 2022

Transforming data using new array shaping formula in excel

 

Hello Community,

 

I'm transforming a set of data into tabular form with the new array shaping formula such as vstack, tocol, chooserow and so forth

 

This is how my data set looks like

Text 1Text 2Date 1Date 2Date 3Date 4
1A1-Nov-223-Nov-225-Nov-227-Nov-22
2B1-Oct-223-Oct-225-Oct-227-Oct-22
3C3-Aug-225-Aug-227-Aug-229-Aug-22
4D19-Jul-2221-Jul-2223-Jul-2225-Jul-22

 

 

This is what i want to achieve

1ADate 11-Nov-22
2BDate 23-Nov-22
3CDate 35-Nov-22
4DDate 47-Nov-22
1ADate 11-Oct-22
2BDate 23-Oct-22
3CDate 35-Oct-22
4DDate 47-Oct-22
1ADate 13-Aug-22
2BDate 25-Aug-22
3CDate 37-Aug-22
4DDate 49-Aug-22
1ADate 119-Jul-22
2BDate 221-Jul-22
3CDate 323-Jul-22
4DDate 425-Jul-22

 

 

This is what i have done so far:

 

I have difficulties in transforming Column text 1 and text 2 into the right rows.

In addition, my set of data has over 180 rows and i can't replicate date 1,2,3,4 using chooserow for 180 times.

 

Is there any expert out there able to advise? Thanks for your help

 

 

  • Melvin_Khoo 

    sample illustrates the logic if number of rows in the table is the same as number of date columns. To take it literally the could be like

    =DROP(
        REDUCE(
            "",
            SEQUENCE(ROWS(Tabelle1)),
            LAMBDA(a,v,
                VSTACK(
                    a,
                    HSTACK(
                        Tabelle1[Text 1],
                        Tabelle1[Text 2],
                        TRANSPOSE(Tabelle1[[#Headers],[Date 1]:[Date 5]]),
                        TRANSPOSE(DROP(CHOOSEROWS(Tabelle1, v), , 2))
                    )
                )
            )
        ),
        1
    )

    But what shall be the logic of the final table if, for example, you have same 5 rows in table but only two date columns?

     

  • Melvin_Khoo 

    An alternative could be Power Query. In the attached file you can enter data in the large blue dynamic table. Then you can enter the number of rows in the small blue dynamic table. In my understanding the number of rows is always the same as the number of columns with dates in your data. For example 5 columns "Date1" to "Date 5" and 5 rows 1,2,3,4 and 5 in column "Text 1".  You can then click in any cell of the green table and right-click with the mouse. Then you can select refresh to update the green result table. The green table and the small blue table can be dragged to the right according to the requirements.

Resources