Forum Discussion

RyanStanford1's avatar
RyanStanford1
Qrew Captain
7 years ago

Formula Field variable set in if statement

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?
  • SuryaExpert's avatar
    SuryaExpert
    Qrew Assistant Captain
    var text variable = Case([Male/Female],"Male","This one is Male","This one is Female");
    $variable
    • HimanshuSharma's avatar
      HimanshuSharma
      Qrew Trainee
      Hi,
      I am trying to figure ways to call  more than 1 variable in an IF or Case statement.
      e.g

      var text var1= <some code>
      var text var2 = <some code>
      
      If( <some conditions> ),
      $var1 $var2
      ,null)​
      This syntax is not valid in QuickBase but I think this should be fairly possible in some other way?

      ------------------------------
      Himanshu Sharma
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        Formula variable names must not contain any characters other than the Alphabet.  So A to Z. Also the expression  need to end on a Semi colon

        var text URLOne = some expression;

        var text URLTwo = some expression;

        If( some condition, $URLOne, $URLTwo)

        ------------------------------
        Mark Shnier (YQC)
        Quick Base Solution Provider
        Your Quick Base Coach
        http://QuickBaseCoach.com
        mark.shnier@gmail.com
        ------------------------------
  • 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?
  • SuryaExpert's avatar
    SuryaExpert
    Qrew Assistant Captain
    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.
  • 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")


  • SuryaExpert's avatar
    SuryaExpert
    Qrew Assistant Captain
    That would work too! Just remember the semi-colon at the end of declarative statements.