Discussions

Expand all | Collapse all

Formula Field variable set in if statement

  • 1.  Formula Field variable set in if statement

    Bronze
    Contributor
    Posted 10-26-2018 14:17
    What I'm trying to do is have a variable that is declared in a formula field, and that variable equals one of two fields, depending on an if statement.

    for example:
    ---------------------------------------------------------------------------------------------------------------------
    var Text variable = "";
    If([Male/Female] = "Male", variable = "This one is Male";,variable = "This one is Female";)

    $variable
    ----------------------------------------------------------------------------------------------------------------------

    This is a simplified version, which focuses on my question. I can't have this field to just be the if statement.

    How can I do this in Quickbase?


  • 2.  RE: Formula Field variable set in if statement

    Bronze
    Contributor
    Posted 10-26-2018 14:34
    var text variable = Case([Male/Female],"Male","This one is Male","This one is Female");
    $variable


  • 3.  RE: Formula Field variable set in if statement

    Bronze
    Contributor
    Posted 10-26-2018 14:43
    Of course! I keep forgetting to look into Case Switches!


  • 4.  RE: Formula Field variable set in if statement

    Bronze
    Contributor
    Posted 10-26-2018 14:56
    The case is strictly if the variable = value right? The issue I'm looking to solve is based on the date in a field, or day of the month... I would have to declare each value right?

    I would have to do 1 = true, 2 = true, 3 = false... instead of being able to do case variable < 3 = true?


  • 5.  RE: Formula Field variable set in if statement

    Bronze
    Contributor
    Posted 10-26-2018 15:28
    I used the case statement as it seemed appropriate for the situation. In other situations, you have to use whatever is more appropriate. it depends on the case at hand.


  • 6.  RE: Formula Field variable set in if statement

    Bronze
    Contributor
    Posted 10-26-2018 17:18
    I figured it out... what I can do is use the if statement in setting the variable, like what you did with Case:


    var Text variable = If([Male/Female] = "Male", "This one is Male","This one is Female")




  • 7.  RE: Formula Field variable set in if statement

    Bronze
    Contributor
    Posted 10-26-2018 17:22
    That would work too! Just remember the semi-colon at the end of declarative statements.