IF() for text strings?

Viewing 7 reply threads
  • Author
    Posts
  • August 19, 2016 at 9:43 AM #18823

    JoeM
    Participant

    It doesn’t appear that IF() supports text strings. Is there a way to do that? E.g. for an address calculation field, it would be great to do something like this:

    ADDRESS1 + “\n” + IF(ADDRESS2 <> “”, ADDRESS2 + “\n”, “”) + CITY + IF(CITY <> “”, “, “, “”) + STATE + ” ” + ZIPCODE

    Then you don’t end up with blank lines for Address2, and random commas if there is no address at all.

    August 19, 2016 at 10:19 AM #18830

    scneophyte
    Participant

    +1

    August 19, 2016 at 12:44 PM #18833

    pmtsc
    Participant

    I would like IF functionality as well if this is possible

    August 19, 2016 at 8:55 PM #18851

    Brendan
    Keymaster

    Unfortunately the math parser I use doesn’t support IF for text values. In fact, it didn’t even support concatenation of strings with the + operator so I had to add that. It would be good to support text though for the IF statement.

    May 13, 2017 at 10:24 AM #23123

    Something new with IF and text strings ?
    I try to wrote a formula like IF({text field}=”XYZ”,”XYZ”,”ABC”) and it always returns XYZ

    Thanks

    May 13, 2017 at 2:26 PM #23131

    Brendan
    Keymaster

    Well the IF statement can now return text values, but the actual condition part must still be numeric in nature. I’ll have to work on that.

    May 17, 2017 at 9:42 AM #23207

    Mike Schwartz
    Participant

    Joe,

    You can get what you want by using the IFEMPTY function instead of an IF function:

    ADDRESS1 + “\n” + IFEMPTY(ADDRESS2,””,ADDRESS2+”\n”) + IFEMPTY(CITY,””,CITY+”, “) + STATE + ” ” + ZIPCODE.

    That will get rid of the blank line for an empty ADDRESS2, and also get rid of random commas. You’ll still get some spaces and line feeds if the address is completely empty, but they won’t be visible. You can tweak the formula further to avoid those, but I wanted to give you an exact analogue to your formula.

    Hope that helps,
    Mike

    May 17, 2017 at 10:08 AM #23208

    Mike Schwartz
    Participant

    The use of IFEMPTY just covers one particular case, and does not provide a robust set of string tests for the Condition part of the IF statement. I could envision:

    IF( string1 [SAME AS] string2, X,Y)
    IF( string1 [CONTAINS] string2, X,Y)
    IF( string1 [BEGINS WITH] string2, X,Y)
    IF( string1 [ISEMPTY], X,Y)

    You could also concoct the reverse operators [NOT SAME AS], [DOES NOT CONTAIN], etc, but why bother? All you need to do is reverse X and Y to reverse the logic. You could also argue to eliminate [ISEMPTY], since string1 [SAME AS] “” accomplishes the same thing.

    Just some food for thought.

    — Mike

Viewing 7 reply threads

You must be logged in to reply to this topic.