Search code examples
arraysgoogle-sheetsfiltergoogle-sheets-formulaflatten

Transform stacked tables of key value pairs to a single key value table dynamically


I want to dynamically convert stacked tables of key-value pairs into a single key-value table.
The input table has hundreds of key value pair tables stacked on top of each other. Every table has 3 columns.
The Demo Sheet

enter image description here

I tried using a healper column with this formula, but it's not feasible in my case.

={ {"Key", "Value"}; { FLATTEN( FILTER(A2:C,D2:D="Key")), FLATTEN( FILTER(A2:C,D2:D="Value")) }}

enter image description here


Solution

  • try:

    ={"Key", "Value"; FLATTEN(FILTER(A2:C, ISEVEN(ROW(A2:A)))), 
                      FLATTEN(FILTER(A2:C,  ISODD(ROW(A2:A))))}
    

    enter image description here

    or:

    ={"Key", "Value"; FLATTEN(QUERY(A2:C, "skipping 2", )), 
                      FLATTEN(QUERY(A3:C, "skipping 2", ))}
    

    enter image description here