I have this string in one single cell (A1):
Apple – 1
Banana – 6
Cherry – 10
Peach – 100
Apple – 1000
Kiwi – 10999
Peach – 44
Fig – 3/100
Fig – 3/100
I need to find a formula that can combine duplicate entries and sum up their values. So the desired output is this (also in a single cell, lets say B1):
Apple – 1001
Banana – 6
Cherry – 10
Peach – 144
Kiwi – 10999
Fig – 6/100
I tried this for hours but cant figure out how to do it. What I tried is to first find unique values. So far, no problem:
=UNIQUE(
ARRAYFORMULA(
REGEXEXTRACT(
TRANSPOSE(SPLIT(A1, CHAR(10))),
"(.*) – [0-9.]+/?[0-9]?"
)
)
)
returns the array of unique values
{"Apple", "Banana", "Cherry", "Peach", "Kiwi", "Fig"}
The best result I could come up with is this formula, to work with Apple and Banana manually:
=ARRAYFORMULA(
{
"Apple" & " – " & SUM(
ARRAYFORMULA(
IF(
REGEXMATCH(
TRANSPOSE(SPLIT(A1, CHAR(10))),
"Apple" & " – [0-9.]+/?[0-9]?"
),
VALUE(
REGEXEXTRACT(
TRANSPOSE(SPLIT(A1, CHAR(10))),
"Apple – ([0-9.]+)/?[0-9]?"
)
),
""
)
)
);
"Banana" & " – " & SUM(
ARRAYFORMULA(
IF(
REGEXMATCH(
TRANSPOSE(SPLIT(A1, CHAR(10))),
"Banana" & " – [0-9.]+/?[0-9]?"
),
VALUE(
REGEXEXTRACT(
TRANSPOSE(SPLIT(A1, CHAR(10))),
"Banana – ([0-9.]+)/?[0-9]?"
)
),
""
)
)
)
}
)
this correctly outputs the array
{"Apple – 1001", "Banana – 6"}
But no matter what I try, I fail to get it to work dynamically for all the unique elements. I feel like I figured out both pieces to the puzzle but I just can't put it together
So the desired output is this:
Is this also in a single cell? – TonguelashTEXTJOIN(CHAR(10), TRUE, [array here])
), so if you can figure out how to make the arrayformula, that would probably be good enough too – Sensitize