Search code examples
google-sheetsgoogle-sheets-formula

Formula for Transposing Specific Columns


I am trying to figure out if there is a formula that can transpose specific columns in a Google sheet.

I have created a data entry tab for users to input data "Input (Data Entry)" (screenshot below), the yellow highlighted column names are the fields that need to be transposed in the output data set.

enter image description here

My goal is to have the data input transform into a formatted data set seen in the "Output (Dataset)" (screenshot below). The yellow highlighted column is the transposed column compiled from the columns in the "Input (Data Entry)" tab. Fields highlighted in orange are fields that are imported from the "Input (Data Entry)" tab, fields highlighted in blue are duplicated entries of the orange fields due to transposed values. Do note for Field 5A - Field 5C, these values essentially repeat thus why they are highlighted in orange.

enter image description here

I have attempted to link the sheet and use transpose on the specific columns but problems arises when I try to copy the formula downwards as the reference rows from the input sheet would jump in the formulas due to spacing created by the transposed values. Is there a formula workaround for this?

Sample Spreadsheet


Solution

  • You can use REDUCE to process those three columns, and stack the retrieved other columns based on the rows of each cell:

    =REDUCE({'Input (Data Entry)'!A1:F1,'Input (Data Entry)'!I1:M1},'Input (Data Entry)'!F2:H5,LAMBDA(a,v,
    VSTACK(a,HSTACK(INDEX('Input (Data Entry)'!A:E,ROW(v)),v,INDEX('Input (Data Entry)'!I:M,ROW(v))))))
    

    enter image description here

    The first part are the headers, you can grab other cells or just type them inside: for example, change {'Input (Data Entry)'!A1:F1,'Input (Data Entry)'!I1:M1} with HSTACK("header 1, "header 2"....., "header 11")