Google-sheets – How to sum all the value inside multiple brackets within single cell in Google Sheets

formulasgoogle sheets

I'm a complete noob to everything that concerns formulas and scripts on sheets but I thought I'd ask if a certain thing was possible:

I have no idea if this is even feasible in a formula or if I'd be better off by doing it manually but basically I'd like to do as follow:

7 (3.4) – Losjon (1.2), Grafenau (2.2)

Right now I have in a cell (left content before the '-') the total sum of numbers in between brackets in the right cell (so 1+2+2+2=7) and in between brackets in that same left cell the sum of "left" numbers (I don't know how to call them but here the numbers in italic so 1+2=3) and the sum of "right" numbers (in bold italic so 2+2=4). I wondered if this could be automatized using a formula?

Best Answer

I have added a new sheet ("Erik Help") to your sample spreadsheet. There you will find the following array formula in D1 (highlighted in green):

=ArrayFormula({"Amount - Total (Male.Female)";IF(A2:A="",,MMULT(VALUE(REGEXEXTRACT(ARRAY_CONSTRAIN(SPLIT(REGEXREPLACE(E2:E,"[^0-9\.\(]","")&REPT("(0.0",10),"("),COUNTA(A2:A),10)&"","\d+")),SEQUENCE(10,1,1,0))+MMULT(VALUE(REGEXEXTRACT(ARRAY_CONSTRAIN(SPLIT(REGEXREPLACE(REGEXREPLACE(E2:E,"\,|\)","~"),"[^0-9\~\.\(]","")&REPT("(0.0",10),"("),COUNTA(A2:A),10)&"~","(\d+)~")),SEQUENCE(10,1,1,0))&" ("&MMULT(VALUE(REGEXEXTRACT(ARRAY_CONSTRAIN(SPLIT(REGEXREPLACE(E2:E,"[^0-9\.\(]","")&REPT("(0.0",10),"("),COUNTA(A2:A),10)&"","\d+")),SEQUENCE(10,1,1,0))&"."&MMULT(VALUE(REGEXEXTRACT(ARRAY_CONSTRAIN(SPLIT(REGEXREPLACE(REGEXREPLACE(E2:E,"\,|\)","~"),"[^0-9\~\.\(]","")&REPT("(0.0",10),"("),COUNTA(A2:A),10)&"~","(\d+)~")),SEQUENCE(10,1,1,0))&")")})

This formula will produce the header and all results for Column D.

Since the formula is quite complex and designed for a unique/custom situation, it is being provided as-is without explanation.