Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorafrank
    • CommentTimeApr 28th 2011
     
    Scenario: Taxes are applicable only when a certain answer is selected for the state field. Taxes only apply in 4 states (a total of 7 choices). I can't figure out how to calculate the tax on conditional answers . I have created conditional fields for the taxes, but I don't know how to display the results in 1 field for a larger calculation for grand total. A simple if then statement would likely work, but I can't figure out how to make that work using javascript.

    Basically, how can I do a conditional calculation based on the conditional answers of a question?
    • CommentAuthordbuschho
    • CommentTimeApr 28th 2011 edited
     
    Hello Adam,

    Do the following:
    1. Create your dropdown list of 7 states.
    2. Mark that field as a variable for calculations (say STATETAX), then set the value for each state's tax as a decimal:
    IN - 0.0875
    DE - 0.0425
    TX - 0.000
    OK - 0.000
    3. In your tax total calculation, use the variable in a formula, like say:
    Number(SUBTOTAL*STATETAX).toFixed(2)

    then your grand total would be something like:
    Number(SUBTOTAL+TAXTOTAL).toFixed(2)

    Make sense for your use case?
    • CommentAuthorafrank
    • CommentTimeApr 29th 2011
     
    It doesn't address the problem of conditional answers. I want the result of any of those state tax calculations to then be a variable in another calculation. However, there is no logic that says to use one of the answer's tax rates if that particular state is selected. I've created a temporary work around to address this for the most part. I have the user verify the state they are using in a 2nd question down if they are in a taxable state. The real problem is that there is no way for the formula to recognize a value for tax based on an ANSWER that already has a variable in it.

    I'm open to any other suggestions. If this were excel, I would have been done in about 15 minutes, but because this is a form builder, conditional formulas are tricky.

    Perhaps Cedric would like to weigh in?
    • CommentAuthordbuschho
    • CommentTimeApr 29th 2011
     
    Okdokie Adam, sorry I couldn't help. I'll see if Cedric has time to take a crack at it for you. Can you tell us which form you're working on?

    The method of doing if statements in your formulas is:
    if(VAR=='value'){calculation}if(VAR=='othervalue'){calculation}

    Happy to help,
    FA Support
    •  
      CommentAuthorcedsav
    • CommentTimeApr 29th 2011
     
    Adam, you can use if/then logic in a field computation. Drew's syntax works above, or you can use the even shorter (a)?b:c notation.

    For instance:

    Formula: (STATE=='TX')?0.5:0
    Variable: TEXASTAX


    Seeing your form would help as well (you can open a support request if needed). As far as I can tell, it looks like Drew's first answer would work too.