1

I'm creating an expense form which asked for costs but in either monthly or yearly amounts. I was thinking I would first create a currency field to ask for the amount. Then add a Choice Box with two options "Monthly" or "Yearly" to designate what that amount is. I will have a list of these expenses such as utilities, insurance, etc.

So at the end of the form, I want to be able to calculate their total expenses. But how do I calculate if an amount is a monthly or yearly value? If it's monthly, then multiply by 12, or yearly, divide by 12. That way I can provide total expenses in monthly and yearly numbers.

1

I am a developer for Cognito Forms.

Assume you have a Currency field called Utilities and a Choice field called Timeframe, with the options Monthly and Yearly. Your calculations would then be:

Monthly Amount

=Utilities / (Timeframe = "Monthly" ? 1 : 12)

Yearly Amount

=Utilities * (Timeframe = "Yearly" ? 1 : 12)

And of course you can just keep adding on additional items to the calculation for each type of cost.

  • Hi Jamie, thanks for the response. This is great, but the calculations are still not quite right which I can look into. But let me ask what does the "1 : 12" do? I'm trying to understand the syntax. Thank you! – Tim C. Feb 12 '15 at 23:09
  • @TimC. this syntax has been a challenge for many of our users, so we may introduce another way to handle conditional statements, like If(condition, true result, false result). The ? : syntax is called a ternary operator and is used to return one of two values based on conditional logic. The syntax is <condition> ? <true result> : <false result). This comes from the C language and therefore also exists in JavaScript as well so it is very familiar to web developers. However, like I said, it is cryptic so we may provide an alternative syntax. – Jamie Thomas Feb 13 '15 at 13:02
  • Hi Jamie, thank you again, this helps out a lot! I was able to get the form to work. If I may ask a followup question? I split up some of the questions to multiple pages to keep the form looking clean. How to I reference variables on different pages? In other words, have a page for Housing budget and a page for Auto budget. But I want to now have a total, how to I add these pages together? Thanks! – Tim C. Feb 18 '15 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.