3
=COUNTIFS(Orders!$T:$T,$B4)

is a code that gives 0 or a +ve result

I use this across 1500 cells which makes the sheet gets filled with 0s

I'd like to remove the Zeros by using the following formula

if(COUNTIFS(Orders!$T:$T,$B3,Orders!$F:$F,""&P$1&"*")=0,
"",
COUNTIFS(Orders!$T:$T,$B3,Orders!$F:$F,""&P$1&"*"))

This calculates every formula twice and increases the calculation time.

How can we do this in 1 formula where if the value is 0 - keep empty - otherwise display the answer

image 1

image 2

2
  • If cell equals 0, then leave it blank But with least calculations Commented Mar 27, 2018 at 20:15
  • Add conditional formatting?
    – tehhowch
    Commented Mar 27, 2018 at 20:30

3 Answers 3

10

I suggest this cell-function:

=IFERROR(1/(1/COUNTIFS(Orders!$T:$T,$B4)))

EDIT: I'm not sure what to add as explanation. Basically to replace the result of a complex calculation with blank cells if it results in 0, you can wrap the complex function in

IFERROR(1/(1/  ComplexFunction()   ))

It works by twice taking the inverse (1/X) of the result, thus returning the original result in all cases except 0 where a DIV0 error is generated. This error is then caught by IFERROR to result in a blank cell.

The advantage of this method is that it doesn't need to calculate the complex function twice, so can give a significant speed/readability increase, and doesn't fool the output like a custom number format which can be important if this cell is used in further functions.

1
  • Downvotes not by me, but I recommend to improve your code-only answer by adding some explanation. That would also help fighting the misunderstanding that StackOverflow is a free code-writing service.
    – Yunnosch
    Commented Apr 7, 2019 at 8:33
9

You only need to set the number format for your range of cells.

Go to the menu Format-->Number-->More Formats-->Custom Number Format...

In the entry area at the top, enter the following: #;-#;""

The "format" of the format string is

(positive value format) ; (negative value format) ; (zero value format)

You can apply colors or commas or anything else. See this link for details

1
  • Is there no equation based formula ... something like what iferror would do for error values - here we need it for "0" values Commented Mar 28, 2018 at 6:21
0

instead of your =COUNTIFS(Orders!$T:$T,$B4) use:

=REGEXREPLACE(""&COUNTIFS(Orders!$T:$T,$B4), "^0$", )

also, to speed up things you should avoid "per row formulae" and use ArrayFormulas

1
  • REGEXREPLACE returns a string. If OP wants to keep cell contents as numbers they must use VALUE(), and VALUE("") will return 0. Commented May 25, 2020 at 6:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.