Efficiently replace 0 with NA

前端 未结 2 1398
闹比i
闹比i 2021-01-29 02:25

I am trying to find a way to efficiently replace zero with NA() in an Excel formula. I know the following works:

=IF(FORMULA = 0, NA(), FORMU

相关标签:
2条回答
  • 2021-01-29 02:58

    Calculation and display can occur in two different locations - why merge operations when you don't need to?

    A1 - =Formula
    B1 - =If(A1 = 0, NA(),A1)

    0 讨论(0)
  • 2021-01-29 03:03

    The general answer is

    =IFERROR(f'(f(FORMULA)), AlternateValue)
    

    where f(FORMUALA) returns an error (any error will do) for values of FORMULA that you want an alternate value for.

    And f'(...) is the inverse of f(...), so f'(f(FORMULA)) returns FORMULA for other values.

    Ensure the first function is applied to the whole of FORMULA. Enclosing it in () guarantees that.

    Secondly, ensure the two functions are applied in the correct order, also achieved using ().

    In this case you want an alternate value for 0 so you can use

    =IFERROR(1/(1/(FORMULA)), NA())
    
    0 讨论(0)
提交回复
热议问题