0

I am trying to find a particular string in a specific range of cells and the sum of the values that are inside the brackets following that particular string and storing the same in another table.

For Example, In Sample Sheet

I am trying to find the string Food in the range C3:C33 and add the values inside the brackets 200,100,150,55,150,120 in Table 1 and store their sum 775 in Table 2.

I wondered if this could be automated using a formula.


Table 1

A B C
Date Day Details
01-01-2022 Saturday Food(200)+Parking(50)
07-01-2022 Friday Food(100)+Shopping(500)+Travel(100)
08-01-2022 Saturday Shopping(200)
10-01-2022 Monday Food(150)+Travel(90+25)
15-01-2022 Saturday Food(55)+Shopping(88)+Parking(73)
18-01-2022 Tuesday Food(150)
22-01-2022 Saturday Food(120)+Movies(300)+Parking(80)
28-01-2022 Friday Parking(120)
31-01-2022 Monday Movies(250)

Table 2

G H
Spending Area Total
Food 775
Travel 215
Movies 550
Parking 323
Shopping 788
1
  • 1
    If there were only a number in parentheses, then a formula like =SUM(ARRAYFORMULA(IFERROR(VALUE(REGEXEXTRACT(C3:C33,G3&"\((\d+)")),0))) would do the job. But a string like "Travel(90+25)" spoils everything. Is it important for you to see just such an entry in brackets?
    – JohnSUN
    Commented Jan 16, 2023 at 13:06

1 Answer 1

0
=QUERY(
   BYROW(
     INDEX(
       SPLIT(
         TOCOL(
           REGEXREPLACE(
             SPLIT(C3:C33,")"),
             "^[+-]",),
           1),
         "(")), 
     LAMBDA(x, IF(LEN(INDEX(x,,1)),
       {INDEX(x,,1), 
          SUM(
            SPLIT(
              " 👍"& 
                REGEXREPLACE(
                  ""&INDEX(x,,2), "([+-])",   "👍$1"),
              "👍"))},))), 
   "Select Col1, SUM(Col2) Where Col2 > 0 Group By Col1 Label Col1 'Category'")  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.