Discussions

Expand all | Collapse all

Formula Field variable set in if statement

  • 1.  Formula Field variable set in if statement

    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

    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

    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

    Posted 06-28-2021 05:52
    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
    ------------------------------



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

    Posted 06-28-2021 06:45
    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
    ------------------------------



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

    Posted 06-29-2021 02:17

    Hi Mark,

    Sorry this was just an example. I am basically trying to execute 2 variables when the condition is true.

    var text varOne= <some code>
    var text varTwo = <some code>
    
    If( <some conditions> ),<--- When this condition = true 
    $varOne $varTwo <-- calling 2 or more variables, possible?
    ,null)​
    
    




    ​​

    ------------------------------
    Himanshu Sharma
    ------------------------------



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

    Posted 06-29-2021 07:40
    That question was answered here.  Ie how to execute sequential API calls.

    https://community.quickbase.com/communities/community-home/digestviewer/viewthread?MessageKey=5e8aaf4e-9601-47cb-80ed-60c0c34b6f10&CommunityKey=d860b0f8-6a48-487b-b346-44c47a19a804&tab=digestviewer#bm5e8aaf4e-9601-47cb-80ed-60c0c34b6f10

    Give it a try and post back with your actual code if you get stuck on the syntax.

    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------



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

    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?


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

    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.


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

    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")




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

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