I have an issue that needs to be resolved in Google Sheets. I need to convert data from one row into multiple rows as follows
link file: https://docs.google.com/spreadsheets/d/1TJtThB-yhd-e_Hk6X_VrgIHSZchaHJM9EGhBNqXrqRU/edit?usp=sharing thanks in advance
Here's a possible solution
=ARRAYFORMULA(
LET(data,B3:G4,
QUERY(
REDUCE(TOCOL(,1),SEQUENCE(ROWS(data)),
LAMBDA(acc,i,
LET(cur_labels,CHOOSECOLS(INDEX(data,i),1,2),
cur_data,CHOOSECOLS(INDEX(data,i),SEQUENCE(COLUMNS(data)-2,1,3)),
VSTACK(acc,
REDUCE(
IF(SEQUENCE(COUNTIF(cur_data,"<>")),cur_labels),
SEQUENCE(COLUMNS(data)-2),
LAMBDA(acc_,i_,
IFNA(HSTACK(acc_,
VSTACK(
IFERROR(
IF(SEQUENCE(COUNTIF(IFERROR(CHOOSECOLS(cur_data,SEQUENCE(i_-1))),"<>")),),
TOCOL(,1)),
INDEX(cur_data,,i_)))))))))),
"where Col2 is not null")))
For each row of the input array:
COUNTIF(previous_columns,"<>")-1
where previous_columns
is the array of columns prior to the current one.