Share via

CONDITIONAL RUNNING SUM

Anonymous
2024-08-24T11:12:59+00:00

I am trying to use the following formula to sum values in column A when the value in Column A is zero however the formula is returning last value instead of summing all value i.e. in cell B4 the value should be 500 instead of 300. Please guide how solve the problem ?

=IF(A2=0,SUM(XLOOKUP(TRUE,B$1:B1<>"",A$1:A1,,,-1):A2),0)

Sample data

A B
200 -
300 -
- 300
100 -
600 -
- 600
-
300 -
600 -
- 600
Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2024-08-24T14:59:56+00:00

Hi FazliWahid,

See if the below formula works for you. Apply this formula in cell B2 and drag it down.

=IFERROR(IF(A2 ="", SUM((INDEX(A$1:A$15, LOOKUP(2, 1/(SUBSTITUTE(A$1:A1, "Value", "") = ""), ROW(A1:A$2))) : INDEX(A1:A$15, MATCH(TRUE, INDEX(A1:A$15 = "", ), 0) -1))), ""), "")

Change the word Value in formula with the appropriate word that you have specified for head of column A.

Note: In order for the formula to work, you will need to replace the zero value cells with empty cells in column A.

Hope this helps.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

10 additional answers

Sort by: Most helpful
  1. Ashish Mathur 102K Reputation points Volunteer Moderator
    2024-08-29T09:19:37+00:00

    Hi,

    In cell D2, enter this formula and drag down

    =IF(C2=0,SUM(INDEX(A$1:A1,XLOOKUP(TRUE,C$1:C1=0,ROW(C$1:C1),2,,-1),1):A2),0)

    Hope this helps.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Ashish Mathur 102K Reputation points Volunteer Moderator
    2024-08-25T23:13:14+00:00

    You are welcome. In cell B2, enter this formula and drag down

    =IF(A2="","",IF(A2=0,SUM(XLOOKUP(1,((A$1:A1=0)+(ISTEXT(A$1:A1))),A$1:A1,,,-1):A2),""))

    Hope this helps.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Ashish Mathur 102K Reputation points Volunteer Moderator
    2024-08-24T23:16:07+00:00

    Hi,

    In cell B2, enter this formula

    =IF(A2="","",IF(A2=0,SUM(XLOOKUP(TRUE,A$1:A1=0,A$1:A1,,,-1):A2),""))

    Hope this helps.

    Was this answer helpful?

    0 comments No comments