Search code examples
excelexcel-formulasumifs

SUMIF with filtered range of values


This formula currently gets me the sum of all the positive values in column D which fall into April 2019 (M column contains dates).

=SUMIFS(D18:D2834,M18:M2834,">="&DATE(2019,4,1),M18:M2834,"<"&DATE(2019,5,1),D18:D2834,">"&0)

I'm trying to change this formula to only sum the values in the D column which are positive OR where the value in the C column contains some text. I can write this condition as

"*some text*"

using wildcards, but I'm not sure how to incorporate it into this formula.

Column C.       Column D        Column M



some text          200           03/08/2020
some more text     500           02/04/2019
bla bla            -100          01/01/2020

Solution

  • Given your explanation in the comments, I would do:

    =SUMIFS(D18:D2834,M18:M2834,">="&DATE(2019,4,1),M18:M2834,"<"&DATE(2019,5,1)) - SUMIFS(D18:D2834,M18:M2834,">="&DATE(2019,4,1),M18:M2834,"<"&DATE(2019,5,1),D18:D2834,"<=0",C18:C2834,"<>*some text*")
    
    1. Sum everything in April 2019
    2. Then subtract the scenario that fits in April 2019 but you DON'T want (the value isn't positive and C doesn't have "some text")

    Why does it work? See the truth table. Given your conditions, the only scenario in April 2019 you don't want to sum is the orange one.

    enter image description here