google-sheetsgoogle-sheets-formula

Google Sheets formula to split a cell that contains a null value


I have data related to Product with the following data example: Data

I want to clean it up into the expected output as follows: Expected Output

For the output, I have tried the formula:

=LET(
  item_code; FLATTEN(A4:A9 & B4:B9 & C4:C9);
  item_name; FLATTEN(D4:D9);
  production_code; FLATTEN(E4:E9);
  
  test_type_1; SPLIT(FLATTEN(F4:F9); CHAR(10));
  test_req_1; SPLIT(FLATTEN(G4:G9); CHAR(10));
  test_type_2; SPLIT(FLATTEN(H4:H9); CHAR(10));
  test_req_2; SPLIT(FLATTEN(I4:I9); CHAR(10));
  
  FILTER(
    HSTACK(item_code; item_name; production_code; test_type_1; test_req_1; test_type_2; test_req_2);
    test_type_1 <> ""
  )
)

but the formula used still produces wrong output and errors. I want to separate each stage from test type and test requirement. Any suggestions for improving the formula?

Here's the test sheet link: https://docs.google.com/spreadsheets/d/1r5wKNfnvC7llG8OlfkAiVmE3qy0MOo6DFoDOBMpt-Jo/edit?usp=sharing


Solution

  • You may try:

    =arrayformula(reduce(tocol(;1);sequence(match(;0/(A4:A<>"")));lambda(a;c;iferror(vstack(a;let(Λ;bycol(index(F4:I;c);lambda(Σ;mid(tocol(split(Σ;char(10)));4;9^9)));
            hstack(chooserows({join(;index(A4:C;c))\index(D4:E;c)};sequence(rows(Λ);1;1;0));Λ)))))))
    

    enter image description here