I've got a spreadsheet listing items with a possible child-parent relation (no grand children, children never come before their parent, but children of different parents can be mixed), and I'd like to list next to each parent its family list with the parent and its children (column C):
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Item | Parent if applicable | Expected: family photo | {=IF(B2:B8="",A2:A8&","&TEXTJOIN(",",1,IF(B2:B8=A2,A2:A8,"")),"")} |
| 2 | Fruit | Fruit,Apple,Banana | Fruit,Apple,Banana | |
| 3 | Apple | Fruit | ||
| 4 | Animal | Animal,Pangolin,Duck | Animal,Apple,Banana | |
| 5 | Pangolin | Animal | ||
| 6 | Duck | Animal | ||
| 7 | Banana | Fruit | ||
| 8 | Thing | Thing | Thing,Apple,Banana |
N.B.: ported from a French LibreOffice with translated function names, and ;s instead of ,s, so the formula may have translation typos
But I don't understand how (or if?) I can refer to the current line of the array to get "the A column of every line whose B matches the current line's A";
I was expecting that using =A2 in cell D2 would mean "3 columns left from the current cell", but no way, as seen in column D hereabove, it's as if I had written =A$2 and I get fruits all over the column (OK still that's less invasive and healthier than an army of pangolins, ducks, and things, but I'm getting away from my goal)
What is the standard, simple way to refer to a cell relative to the current's one in an array formula?
Other attempts:
- Although
{=OFFSET(A2,ROW()-2,0)}(seen in a Google Spreadsheet question) works as a standalone array formula, for example in column E, integrating it in the full formula (…,IF(B$2:B$8=OFFSET(A2,ROW()-2,0),A$2:A$8,"")…) only returns blank cells - using a non-array formula (replicated to the subsequent lines) fails (blank cells too)
- I ended up creating 1 dedicated array formula per cell but doesn't it defeat the purpose of array formulas?
(LibreOffice 25.2.2.2)
Bonus question
If a solution can be found for at least getting this list of children,
then a hint on prefixing with the head of family (Fruit, or Animal,) would be welcome.
The simplest way (concatenating it at the start with a ",") lets a trailing , when the entry has no child in its family (Thing,),
so for now I have a dirty solution that then REGEX(A2&","&TEXTJOIN(…),",$","").
But I suspect it would be possible to make the family head enter the IF with an OR ("take column A of the array when (array row's column B equals current row's A) OR (array row is the current row)").
=IF(B2:B8="",A2:A8&","&TEXTJOIN(",",1,IF(B2:B8=A2,A2:A8,"")),"")shows the problem that matches your explanation, so this must have been what you actually attempted.A2:A8&","&would pollute, it makes clear we've got a strange Animal Banana). Additionally I fixed theA7s toA8s (I forgot to adapt the formulas when I added theThingline later, to show the "without children" case).