Boolean to number

Hello all,


Is there a way to convert a TRUE/FALSE boolean value in Numbers to an integer (1/0)? Elegantly, without using the IF function, which is slow.


Thank you!


Vidu

Posted on Jul 13, 2021 12:01 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 13, 2021 4:54 AM

If you are trying to use it in a function that won't accept it as a boolean, multiplying it by 1 in the formula will do it except it will also put a blue triangle in the cell. If you are trying to avoid the blue triangle, your choices are limited. There is no elegant conversion that I am aware of. I don't know why Numbers feels the need to warn about using true/false as numbers but it does. And it does not give you the option of ignoring those blue triangle warnings, which makes it doubly painful.


If it is a column of booleans (column B for example), you can insert a new column and use the formula =B*1 which will convert the booleans to numbers (with the blue triangles). Use that column of numbers in your downstream formulas then hide the column after everything is set up.


There are plenty of non-elegant formulas in addition to IF or IFS. Maybe COUNTIF would be a contender on speed. It is a concise formula at least. IF is almost assuredly faster, though.

=COUNTIF(B2,TRUE)


5 replies
Question marked as Top-ranking reply

Jul 13, 2021 4:54 AM in response to Devapathiraja

If you are trying to use it in a function that won't accept it as a boolean, multiplying it by 1 in the formula will do it except it will also put a blue triangle in the cell. If you are trying to avoid the blue triangle, your choices are limited. There is no elegant conversion that I am aware of. I don't know why Numbers feels the need to warn about using true/false as numbers but it does. And it does not give you the option of ignoring those blue triangle warnings, which makes it doubly painful.


If it is a column of booleans (column B for example), you can insert a new column and use the formula =B*1 which will convert the booleans to numbers (with the blue triangles). Use that column of numbers in your downstream formulas then hide the column after everything is set up.


There are plenty of non-elegant formulas in addition to IF or IFS. Maybe COUNTIF would be a contender on speed. It is a concise formula at least. IF is almost assuredly faster, though.

=COUNTIF(B2,TRUE)


Jul 13, 2021 12:23 AM in response to Devapathiraja

You could use MATCH & INDEX or one of the LOOKUP functions, but I doubt it would be significantly faster than IF.


Or try IFS(B2,1,true,0) Where B2 is the cell containing a TRUE or FALSE result.


IFS tests each value in turn, presents the result of the first that tests 'true.

In this formula, if B2 contains 'true' the formula returns 1, and exits.

If B2 contains 'false', ifs moves on to the next pair. 'true' returns 'true', IFS returns the value paired with that test ( o ) and exits.


Regards,

Barry

Jul 14, 2021 1:11 PM in response to Devapathiraja

" Hopefully this will be fixed in the future."


The warning triangle has been a feature acting in the same manner since the introduction of Numbers version 1 (the example below is from Numbers '09 v2.3).


Changing that behaviour requires a change in the software, something that is outside the scope of these user to user communities.


Send your Feature Request directly to Apple via the Provide Numbers Feedback menu item in the Numbers menu.


Regards,

Barry

Jul 15, 2021 6:48 AM in response to Barry

Barry,


Is there a way to ignore the warning in the latest versions? The warning itself isn't so bad but I see no way to get the blue triangle to go away. It comes up in other functions, too, like SMALL or LARGE when the range includes cells that are not numbers. Some formulas to return multiple matching values rely on those functions and it makes for more complicated formulas just to avoid blue triangles.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Boolean to number

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.