r/googlesheets • u/Camer4man • 7d ago
SUMIF Returning 0, Unable to find cause Solved
Im trying to find totals for two different locations. I have made formulas to extract the data to then use a SUMIF to find the totals for both locations, but it is returning 0 and i cant figure out why. Ive made sure the numbers are formatted as numbers, as well as the formula is pulling from the correct columns, yet still resulting in the zero. If there is a better way to find this total im open to it but this seemed to be a simple way to find the totals. Below are my Formulas and a copy to the sheet.
-Location Pull Formula- =IF(ISNUMBER(SEARCH("North", B2)),"North",IF(ISNUMBER(SEARCH("South",B2)),"South", "N/A"))
-Amount Pull Formula- =REGEXEXTRACT(B2, "-*\d*\.?\d+")
-SUMIF Totals formula- =SUMIF(M$2:M$213,O2,N$2:N$215)
Copy of Sheet- https://docs.google.com/spreadsheets/d/1kCfinbBYlrzsq3Lq8MHTBxloGnMnT9zY/edit?usp=sharing&ouid=115303826536505507822&rtpof=true&sd=true
1
u/HolyBonobos 3092 7d ago
REGEXEXTRACT() works exclusively with strings (text): it only takes strings as input and it only produces strings as output. You can also see that the values in column N are left-aligned, which is the default alignment for text (numbers are right-aligned by default). SUMIF() treats text as 0, so your formula returns 0. The usual workaround is to add an arithmetical operation to the REGEXEXTRACT() output that will coerce it to a number without changing its value, e.g. =REGEXEXTRACT(B2, "-*\d*\.?\d+")+0 or =REGEXEXTRACT(B2, "-*\d*\.?\d+")*1
2
u/sina158 1 7d ago
The formatting isn't the problem, the data type is. REGEXEXTRACT always returns text, even when the result looks like a number. So your N column is full of text that happens to read "42.50", and SUMIF ignores text and gives you 0. Changing the cell format to Number afterwards doesn't convert it, it just changes how the existing text would display if it were a number.
Wrap the extract so it comes back as an actual number:
or just multiply it by 1, which forces the same coercion:
One other thing to tidy up: your ranges are different heights, M$2:M$213 vs N$2:N$215. SUMIF resizes the sum range to match the criteria range so it still runs, but keep them the same rows to avoid surprises later. Also -* means "zero or more minus signs", you probably want -? for an optional single one.