Calculation to insert a number based on other field’s text

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Using Tap Forms 5 Calculation to insert a number based on other field’s text

Viewing 5 reply threads
  • Author
    Posts
  • April 1, 2025 at 5:06 AM #51764

    phloem
    Participant

    Field “location” has a pick list. Each location has a known kilometer distance.

    I want a calculation field to give a number depending on the “location”. For example, the calculation field will insert “27” when the location is “ABS”. If the location is “Miya”, then “22” will be inserted.

    I’ve tried the if and if equal but I can’t get it to work. What should the equation be for the above example?

    • This topic was modified 4 weeks, 1 day ago by phloem.
    April 4, 2025 at 8:57 AM #51781

    Brendan
    Keymaster

    The IF() function is used for comparing numbers. The IFEQUAL() is for comparing text.

    IFEQUAL([Location]; "Miya"; 22; 0)

    So for your Location field, if it’s equal to “Miya”, the number 22 will be returned, otherwise 0 will be returned.

    Set the Result Type to Number. Unless you want the text version of 22 or 0 to be returned, in which case you would set the Result Type to Text and use quotes around the numbers:

    IFEQUAL([Location]; "Miya"; "22"; "0")

    P.S. the [] around the field names are just to denote they’re fields and not text. Unless you’re writing it on iOS in which case you type it in exactly like that. On macOS you just double-click on a field to insert it into your formula.

    Thanks,

    Brendan

    April 11, 2025 at 8:06 AM #51825

    phloem
    Participant

    Great thank you. Ok. What should the calculation needs to includes multiple “if”. For example, if “Maya” then 22, if “ABS” then 27, if “Tom” then 15, otherwise 0?

    • This reply was modified 2 weeks, 5 days ago by phloem.
    April 11, 2025 at 8:12 AM #51827

    phloem
    Participant

    would it be like this?

    IFEQUAL([Location]; “Maya”; 22; IFEQUAL([Location]; “ABS”; 27; IFEQUAL([Location]; “Tom”; 15; 0)))

    April 11, 2025 at 1:27 PM #51828

    phloem
    Participant

    Yes. this is working

    April 11, 2025 at 9:31 PM #51834

    Brendan
    Keymaster

    Glad you got it working. With the Calculation field, it can get pretty tricky to follow all the nesting. IF / THEN / ELSE, and so on.

    That’s why when things get complicated like that, using a Script is much simpler I feel.

Viewing 5 reply threads

You must be logged in to reply to this topic.