5

This is the scenario. I need to get the sum of the values until it reaches a blank cell. After that it should start again calculating the sum after the blank cell. I need to add the fat and carbs of every ingredient of each dish individually. enter image description here

This is the expected result. That for each of hundreds of dishes. In this case I entered the data manually:

enter image description here

I tried with this but is adding all of the data from the column:

IF(SUM(C3:C)="","",SUM(C3:C)))

I also tried with this formula but is not working:

IF(C3:C="","",SUM(INDIRECT(ADDRESS(ROW(C3:C),COLUMN(C3:C400))&":"&"C"&MIN(ARRAYFORMULA(IF(C3:C400="",ROW(C3:C400),""))))))

This is the spreadsheet in case you need it.

Thanks in advance for all the help.

1 Answer 1

13

I would just make a small adjustment to your formula:

IF(C2="",SUM(C3:INDEX(C3:C,MATCH(TRUE,(C3:C=""),0))),"")

so the first total is 11 instead of 9.

enter image description here

This is an (experimental) array-formula version based on numbering each group using the presence of a Dish in the first row of each group as a marker:

=ArrayFormula(if(A2:A="","",vlookup(countifs(A2:A,"<>",row(A2:A),"<="&row(A2:A)),
query({C2:C,countifs(A2:A,"<>",row(A2:A),"<="&row(A2:A))},"select Col2,sum(Col1) group by Col2"),2)))

enter image description here

4
  • Do you have any approaches to achieving this with ArrayFormula? Commented Apr 30, 2021 at 19:51
  • I'm thinking if you numbered each group (maybe using countifs) you could do a 'group by' query to find the sum for each group? Will need to experiment with it.
    – Tom Sharpe
    Commented May 1, 2021 at 6:32
  • 1
    This is what I had in mind: =ArrayFormula(if(A2:A="","",vlookup(countifs(A2:A,"<>",row(A2:A),"<="&row(A2:A)), query({C2:C,countifs(A2:A,"<>",row(A2:A),"<="&row(A2:A))},"select Col2,sum(Col1) group by Col2"),2)))
    – Tom Sharpe
    Commented May 1, 2021 at 6:50
  • Excellent, thanks. I will start with this and let you know how it goes! Commented May 3, 2021 at 17:08

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.