简体   繁体   中英

excel count/sum stop count/sum match?

I have tried to see if this question has been asked before, but I can't seem to find an answer.

I have a column of cells (>3000 rows), with either a value of 1 or 0 (call this column A). The value will depend on the value in column B (which will contain either a value or nothing). The values in column B are a SUMIFS function based, summing from column C, and based on months in column D.

The values in B are paid out on the first business day of the next month. So, the SUMIFS function will calculate the dates that match the last month. This works well in theory, however, not every first business day is the first day of the month. This leads the SUMIFS function to not include everything in the correct month, and allows for some discrepancy, which, when you are dealing with people's money is not great. Further, this discrepancy is compounded across multiple periods (in some cases, there are over 100 periods, and a discrepancy of $1 in period 1 amounts to nearly $1000 in period 100)

What I am wondering is:

Is there any way that I can tell the SUMIFS function (column B) to stop when the value in column A is 0? This would tell the SUM function start the summing from the current value in column B and continue the function to the cell below the preceding value in column B.

I've seen suggestions that the MATCH function may work, but I can't see how to do this with either COUNT or SUM.

For security reasons, this solution needs to be entered into the cell, and can't be VBA. Also, it can't be too large, as it will need to be replicated across 200 worksheets in the workbook (not my file originally, and I would have done it differently, but that is another story). There is no problem entering another column or two if that is required.

Any help is gratefully appreciated.

EDIT:

Unfortunately, I can't post an image of the screenshot. I've included a similar screenshot (columns are not the same layout, but hopefully it gives the idea) here:

Rates calculations

The SUMIF formula is (for B2)

=SUMIFS(C2:C35,D2:D35,D2-1,A2:A35,1)

This works fine if I want all the values in the month, irrelevant of when the payment was made.

However, what I need the formula to do is:

SUM (C2:C35,D2:D35,D2-1, but stop when the first 0 is encountered in A2:A35)

Thanks

The INDEX function can provide a valid cell reference to stop using a MATCH function to find an exact match on 0 .

This formula is a bit of a guess as there was no sample data to reference but I believe I have understood your parameters.

=SUMIFS(C2:index(C2:C35, match(0, A2:A35, 0)), D2:index(D2:D35, match(0, A2:A35, 0)), D2-1)

This seems to be something that will stand-alone and not be filled down so I have left the cell addresses relative as per your sample(s).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM