# How to add discount formula into Form Calculation widget based on selections made

**fieryfoods**Hi,

I need to include discounts formulas in the Calculation Widget which will then be reflected in my PayPal Payment Wizard ("Get total from Calculation").

The formula needs to accomplish the following:

Select 4 Subcategories and Pay for 3 (-$80)

Select 7 Subcategories and Pay for 5 (-$160)

Can you help?

**Ben**I took a look at your jotform and I can see the following:

Discounts

Select 4 Subcategories and only pay for 3! (an $80 savings)

Select 7 Subcategories and only pay for 5! (a $160 savings)Under it is however:

Product #1 - Select Category(s)

Product #2 - Select Category(s)

Product #3 - Select Category(s)I presume that the 4 subcategories would be the options under these form collapse tools?

If not, could you please give us a bit more details as to how you wanted to connect it all together?

Thank you.

**fieryfoods**Yes, the subcategories are under the form collapses -- for now the checkboxes only appear under Product #1, but each product will have all those checkboxes underneath them.

- JotForm Support
**EltonCris**@fieryfoods

Thanks for your reply.

I think there's a workaround but we need a few more details. How are you going to count the subcategories, is it when any of the options are selected like the following?

In the picture below, there are 3 subcategories filled. Does this mean 3 subcategories are selected?

Or are the counts based on the numbers of options checked?

Please let us know before we can try out different workarounds. My colleague might also have something to add.

Thanks.

**fieryfoods**Thanks for the response.

The counts are based on the numbers of options selected. For instance, in your screenshot above there are 7 subcategories selected (not 3), so the calculation widget should discount in the amount of $160 (each subcategory = $80). This would constitute select 7 pay for 5. I need to do the same thing for select 4 pay for 3 (a discount of $80).

Hope this helps.

- JotForm Support
**EltonCris**@fieryfoods

In that case, it would be pretty easy then. :)

First, you have to count the number of subcategories selected.

To do that,

1. Add another form calculation widget to your form, label it "subcounter" or to anything you want. Then hide it if you want (right click the field > hide field).

2. In the calculation wizard, use the

**COUNT**function to get the numbered of selected options per field. Then add them to get the total number of selected subcategories. Check this visual animation.Sample form: http://form.jotformpro.com/form/51127223556955?

Now you have the total number of selected subcategories, you can proceed with creating the discounts by using "Update field value" condition.

Example:

You can add more conditions for the rest of the discounts.

E.g.

If subcounter is greater than 8, then subtract the total with the number you want like 160.

If you want us to go more in detail or if you need further assistance, let us know. We'd be happy to help. Thank you!

**fieryfoods**I got as far as setting up the additional Calculation Widget. Beyond that I don't see "Total" as an option in the "Output to Field" section.

This is confusing. Can you go in more detail?

**fieryfoods**Nevermind! I figured it out!

Thanks for your help! :)

**Ben**In my colleague's name, you are welcome and I am glad that you were able to find your way around his detailed answer :)

Do let us know if you have any further questions or issues setting it up and we would be happy to assist.