Search code examples
libreofficelibreoffice-calc

How to set a cell to 1 if two previous cells are the same in Libreoffice Calc?


I am trying to use COUNTIF to return 1 if two previous cells contain the same string. For example:

|  A    |  B    |  C  |
| ----- | ----- | --- |
| hello | hello |  1  |
| world | hello |  0  |

How can I do this in Calc?


Solution

  • The formula =COUNTIF(A1;B1) does produce the desired results. That's because it counts all cells in range A1 that equal B1. Since the range A1 only contains a single cell, it will either result in 1 or 0. Documentation: COUNTIF.

    However, that is not particularly straightforward, at least not for your example. The suggestion from @tohuwawohu is clearer.

    =IF(A1=B1;1;0)
    

    Alternatively, use the elegant =(A1=B1), although it requires somewhat more understanding of how Calc works.