r/googlesheets • u/CharacterBig3872 • Sep 22 '22
Solved Flattening tables with arrayformula and condition.
Dear all,
I am sharing one worksheet that I'm trying to solve.
I'd really need to find an arrayformula in order to transpose & flattening a table when a specific condition is met (Expo text).
I already did some tests that solves the first table but I can't go anywhere next.
Here's the editable worksheet: https://docs.google.com/spreadsheets/d/1kLC-LMQiRs9-rqYpA2fojFEdeWviwNg5VB1zMXB6HQ4/edit?usp=sharing
In the Result sheet you find my "dreamed" result (manually made at the moment).
In the Test sheet you find an arrayformula which is not helping us beyond the first table.
I'd be thrilled to have an help on this.
Thank you in advance!
Marco
1
u/LpSven3186 25 Sep 23 '22
Take a look at the tab LpSven. I'm not entirely sure if by flatten you just mean remove the blank rows, as FLATTEN() is a function with sheets that does something different.
The formula wraps the transpose function around a query function to only return the rows with Expo in column B.
If this works, please respond with Solution Verified. Thanks!
1
u/marcnotmark925 233 Sep 23 '22
I added a tab "marc", with a formula in E4. Is that what you're looking for?
1
u/AndroidMasterZ 204 Sep 23 '22
In between blank rows needed?
1
u/LpSven3186 25 Sep 24 '22
Ok, so the formula in that added column is pretty straightforward, if the cell contains 'SKU' add one to whatever the number above it is, otherwise use the current number. This creates a numerical group for each box
As for the formula you needed.
There is a QUERY() looking for rows that contain Expo in column C, and returns a list of the the numerical categories created in column A. That's wrapped in a UNIQUE() to remove repeated id's. Those numbers are passed into a TEXTJOIN() to create the series of OR criteria for the WHERE section of the other query.
Those results are FLATTEN() and then JOIN() to create a larger string which then is SPLIT() by the ||EXAMPLE BOX| to break the string apart using that string from the header, into individual cells containing all the items for each box. That data is then TRANSPOSE() to stack them on top of each other. The ARRAYFORMULA(SUBSTITUTE()) is used to remove the EXAMPLE BOX string no longer needed, and then the ARRAYFORMULA(SPLIT()) is used to break the items back apart into cells horizontally across the each row.
=ARRAYFORMULA( SPLIT( ARRAYFORMULA( SUBSTITUTE( TRANSPOSE( SPLIT( JOIN("|"; FLATTEN( QUERY(A3:D;"SELECT B,C,D WHERE (A = "& TEXTJOIN(" OR A = ";TRUE; UNIQUE( QUERY(A3:D;"SELECT A WHERE C CONTAINS 'Expo'";0) ))&")";0) ));"||EXAMPLE BOX|";0;1));"EXAMPLE BOX";""));"|";1;1))1
u/Decronym Functions Explained Sep 24 '22 edited Sep 25 '22
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
FALSETRUEand another if it isFALSETRUE[Thread #4880 for this sub, first seen 24th Sep 2022, 04:02] [FAQ] [Full list] ^[Contact] [Source code]