问题
I am trying to get the sum of the following data below but I'm stuck in formulating the logic. Basically, what I am trying to get is the sum of all settled amount per month. I have accomplished that using SUMIFS. However, I want to be able to take into account the Code column. Please see sample data below.
MONTH |CODE |CONTRIBUTION|STATUS
JANUARY |CS-111|500 |Settled
JANUARY |CS-121|500 |Settled
FEBRUARY|CS-131|200 |Settled
FEBRUARY|CS-131|200 |Waiting
FEBRUARY|CS-141|300 |Settled
MARCH |CS-151|400 |Waiting
MARCH |CS-161|700 |Settled
Please see the data for February. We have two codes, CS-131 and CS-141. For CS-131, only the first entry is settled while the second one is waiting. For CS-141's only entry, the status is settled. Given this, I want the formula to disregard counting the amount for CS-131 since both entries are not settled but continue to add the amount for CS-141 since it is settled.
This is my formula so far.
=SUMIFS($C$2:$C$8, $A$2:$A$8,"February", $D$2:$D$8, "Settled")
Any ideas what kind of function I can incorporate to this?
Many apologies if this question has been asked before. Thank you in advance.
回答1:
Switch to SUMPRODUCT
'
=SUMPRODUCT(C2:C8,--(A2:A8="FEBRUARY"),--(COUNTIFS(A2:A8,A2:A8,B2:B8,B2:B8,D2:D8,"Waiting")=0))
How it works:
C2:C8
- the values to be summed--(A2:A8="FEBRUARY")
1
or0
for matching month--(COUNTIFS(A2:A8,A2:A8,B2:B8,B2:B8,D2:D8,"Waiting")=0)
-1
or0
for fully settled codes
3.1.COUNTIFS(A2:A8,A2:A8,B2:B8,B2:B8,D2:D8,"Waiting")
- counts for each Month and Code, how many are Waiting.
3.2COUNTIFS(...) = 0
-True
orFalse
for count = 0
3.3--(...)
- turns theTrue
/False
into1
/0
回答2:
If I understand your data and question correct then you can just do a subtract of the sumifs with "waiting".
=SUMIFS($C$2:$C$8, B2:B8,"CS-131", $A$2:$A$8,"February", $D$2:$D$8, "Settled")-SUMIFS($C$2:$C$8, B2:B8,"CS-131", $A$2:$A$8,"February", $D$2:$D$8, "Waiting")
If there is a waiting then that sum is subtracted from the settled sum and results in 0.
If you want to make negative numbers 0 because there is no settled but only waiting then you can just wrap the sumifs()-sumifs() with a max().
=MAX(0,SUMIFS($C$2:$C$8, B2:B8,"CS-131", $A$2:$A$8,"February", $D$2:$D$8, "Settled")-SUMIFS($C$2:$C$8, B2:B8, "CS-131", $A$2:$A$8,"February", $D$2:$D$8, "Waiting"))
If the result is negative then 0 is displayed, else the sum.
Edit: added the condition that it should only sum "CS-131". It's hardcoded in the formula but that can easily be a cell reference.
来源:https://stackoverflow.com/questions/58516598/exclude-addition-in-sumifs-if-unique-value-is-not-in-the-same-status-in-excel