Variable Tutorial with Calculations

I was watching a tutorial by Jeanette titled Adding Data Entry Fields. The tutorial did a great job of showing how to enter text fields. The example she used also showed how it is possible to have some numberical entries for the user and at the end it would calculate a result.

The example was about a 401(K) plan and how the employee could enter a dollar amount, number of years and a percentage to get a result. Is there a tutorial that covers a similar type of calculation?

I did look at the tutorial for Adding Number Variables but it only demonstrated how to assign a numerical value for a choice. It did not show how to do a calculation.

Thanks for the tutorials and I hope there is one for calculations or that you can make one.

Jeffrey Riley

23 Replies
Jeanette Brooks

Hi Jeffrey! I did a quick screenr on how the calculation slide was built, but maybe it would help to also take a peek at the slide itself so you can deconstruct:


Published demo

Source file

The slide asks the learner to enter 3 items: their salary, the percent they plan to contribute to their 401k, and the number of years till retirement. When they click the Calculate button, a layer appears which shows them the total amount of matching funds the company will contribute on their behalf.

Here's the logic behind the calculations: 

  • I create a variable called Match Calc which is used to display the total on the Results layer. I also created variables for the match percent, salary, and years till retirement.
  • I have a trigger on the base layer which initially sets my Match Calc value equal to the salary, but then on the results layer we perform some calculations on that number to get to the final result.
  • When the learner hits the Calculate button, triggers on the Results layer take the salary, multiply it by the matching percentage, and then multiple by the number of years till retirement. 

I also have a different layer which pops up if the learner tries to hit the Calculate button without entering all the required information.

I hope that helps!

David Lindenberg

Thanks for asking the question Jeffrey and thanks for the example Jeanette.

I built a similar tool and I have it working fine.  The user enters 3 numbers and they perform the calculation.  Is there a way to reset the fields so that they can try again with different numbers?  Ideally I'd like them to click a Reset(!) button so it clears the values and they can play with as many numbers as they want.

Jeanette Brooks

Hi David! Phil's idea is a good one - if your interaction is like the the 401k example posted above, you could perhaps add some triggers to the "Thanks" button on the layer called Results. That way, learners could close the layer and reset the values all with one click. Here's how the triggers would look:

Ashley Terwilliger

Hi Brent, 

This thread is a bit older, so I'm not certain if folks are still subscribed so you may want to message them directly using the "contact me" button on their profile to see if they're able to share what they ended up doing. You may want to also look at investigating what options you have if you were to use Javascript to work with multiple decimal points in variables. It may be something the community can assist with, but you may want to begin by reviewing the best practices here. 

Leslie McKerchie

Hi Rakesh,

I just responded to your question here, and this conversation may shed a little more light on what you want to do.

Tracking in a text file or database is not something I can assist in supporting. As I mentioned in the other conversation, we recommend publishing to an LMS.

Hopefully, someone in the community will be able to chime in and help you out here.

Laura Ingle

I have data input fields where user can input numbers, and I have it set to calculate the numbers automatically without clicking a "calculate button." 

For example: 

When a numeric input loses focus, set to typed value and add to the tally. 

Or alternatively, when numeric input variable changes, add the variable to the tally.

How can I set the tally variable to adjust properly when a user changes an input field. I get how the calculation button works and can make adjustments by setting the tally variable to zero when clicked and placed at top of trigger list, but, I don't want to use a calculate button. I want it to tally automatically. Any ideas? 


Wendy Farmer
Laura Ingle

I don't want to use a calculate button. I want it to tally automatically

Hi Laura

unfortunately for any input field SL waits for the field to lose focus before it validates the the user needs to move from that field using some action. I'd love for it to calc automatically...if anyone has worked out how to do it I'd be interested as well.

Wendy Farmer

Hi Laura

I know what you're trying to do but it won't work with the way SL works until the field loses focus so when the user gets to the last field unless they do something outside of that field it won't calculate. Also if you go back and change a field it calculates when you move to another field but if you happen to click in other fields (similar to tabbing fields) it keeps calculating. It's a limitation of the way SL validates entry fields so I think JS will be your only option.

Now that you've shared the slide someone more technical than me maybe able to help @philmayor @owenholt

Laura Ingle

I agree. It's going to take some scripting to make this work. I've tried so many ways around it to reset the variables (on clicks of input, on press of key, tried playing around with some JS, etc.) and to no avail. Then I get the NaN values. Eek. I'm not really good at JS, so hopefully by putting the file out there I can get more feedback. Someone has to have done this before. Thanks for your help! I appreciate your support! 😊

Get Outlook for Android