Search code examples
excelgoogle-sheetsexcel-formulagoogle-sheets-formula

Is there a way to convert a given table to another table in excel/google sheets using a combination of formulas? as the example in the below images


FROM THISTABLE TO THIS TABLE

I tried to generate formulas for the same using chatgpt, but the results were not apt.


Solution

  • Here's another solution:

    ={"Village","Class","Team";
      ARRAYFORMULA(
        QUERY(
          SPLIT(
            TOCOL(
              TOCOL(TOCOL(A2:A,3)&"ζ"&B1:C1)&"ζ"&
              MAP(TOCOL(B2:C,3),LAMBDA(n,SEQUENCE(1,n)))),
            "ζ"),
          "where Col3 is not null"))}
    

    enter image description here

    This formula is a variation of the standard unpivoting formula.