Forum Discussion

JeremyBirkey's avatar
JeremyBirkey
Community Member
3 months ago

Adding and subtracting variables

In my attached file, I have indicated the column containing the variables that I am adding to the "Total Spent" at the bottom. When the drop down selection changes, the addition works as expected. However, when I change any of my selections to lesser amounts, how would I set up the triggers so the Total Spent decreases? Is this even possible with drop-down menus?

Any insight is appreciated. I was able to achieve a lot of the conditions I wanted for this activity, but can't seem to get this to work.

  • You need to keep track of the previous as well as the current value from each dropdown to know if the total should go up or down. I would probably make an additional variable for each, suffixed with _prev. I would also create another variable for each suffixed _deltaValue (to track the net chnage between the current and previous selection). 

    Set all to 0 to start. Upon selection, set the current variable. Use trigger logic to set _deltaValue to equal the difference between the current and previous value. Then set the previous to equal the current value so its ready for any future selection changes.

    Finally, use the _deltaValue for each to add to the running total. That way, increases or decreases in cost will automatically be accounted for by the positive or negative _deltaValues.

    You could use some JavaScript to consolidate and simplify the calculations without all the triggers, but this approach should work too.

    • JeremyBirkey's avatar
      JeremyBirkey
      Community Member

      Thank you Nathan! I wanted to follow up that I have been able to make headway with one of the drop-down logic using your advice.