+ Reply to Thread
Results 1 to 3 of 3

Simplifying IF functions

  1. #1
    Registered User
    Join Date
    08-28-2010
    Location
    Earth
    MS-Off Ver
    Excel 2019
    Posts
    14

    Simplifying IF functions

    Suppose I have this formula:

    IF( [Complex Formula]=0, "Zero", [Complex Formula] )

    Imagine that the [Complex Formula] is extremely long.
    It seems silly to have to write the Complex Formula twice, and it makes it harder to read the IF function at a glance.

    Is there a way around this?

    Keep in mind the above formula is just an example, this is more a generalized question regarding the IF function.

    Cheers,
    Dave.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Simplifying IF functions

    There are various approaches but it all rather depends on the nature of "Complex Formula" ... ie what it returns (data type), what it is you're looking to account for.

    Double Evaluation is often inefficient... from XL2007+ onwards MS finally decided to give us the looooooong overdue IFERROR function which means we can handle errors without need for double evaluation irrespective of data type consistency of value being returned.

    Prior to XL2007 avoiding double evaluation with formulae alone can be cumbersome and the techniques available will only be applicable in certain situations...

    Continuing the error theme - assume your calculation returns a number or an error and you wish to return 0 instead of an error value:

    Please Login or Register  to view this content.
    Here we add the handler without need for double evalution of complex formula

    The same logic can be applied where text is being returned (as long as string does not exceed the char limit)

    Please Login or Register  to view this content.
    However, it follows that if the data type returned is inconsistent (might be number, might be text) and you wish to preserve the value in it's original form (ie if number keep as number) then the above approach will not work.
    Similarly if you're looking to handle a specific (valid) value then the above might not be feasible either [need to know full logic]

    The most basic (yet best of all) approach is to split the calc. into two separate cells:

    Please Login or Register  to view this content.
    ie A1 acts as an intermediate cell and may/may not be visible to end user - B1 is the final result cell (references purely hypothetical of course)

    This approach not only ensures [complex formula] is calculated only once but also allows for greater flexibility in terms of B1 being able to manipulate the resulting A1 value in a multitude of ways.
    Last edited by DonkeyOte; 08-31-2010 at 08:25 AM.

  3. #3
    Registered User
    Join Date
    08-28-2010
    Location
    Earth
    MS-Off Ver
    Excel 2019
    Posts
    14

    Re: Simplifying IF functions

    Once again, many thanks Donkey!
    Great to get such quick responses on this forum!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1