Question posted 2013 · +10 upvotes
I have boolean values in a column:
A
1 TRUE
2 FALSE
3 TRUE
4 TRUE
I realize that in Excel =TRUE+TRUE returns 2 and =TRUE+FALSE returns 1 which implies TRUE is equal to 1 and FALSE is equal to 0. However, SUM(A1:A4) always returns 0 no matter whether it is array formula style… I would expect it to be 3 (the number of TRUE in the range).
One way to get 3 is to use {=SUM(IF(A1:A4,1,0))} (array formula style), which I find redundant… Could anyone think of a simpler solution than that?
Accepted answer +10 upvotes
You can try prefixing the range with -- and entering as an array. The -- will convert the booleans into their integer equivalents:
=SUM(--(A1:A4))
Per the documentation on the SUM function:
If an argument is an array or reference, only numbers in that array or reference are counted. Empty cells, logical values, or text in the array or reference are ignored.
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- How should I escape commas and speech marks in CSV files so they work in Excel? +136 (2012)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
excel solutions on this site
.