How to make a sum work if one field is not filled out

I’m doing an addition but sometimes users do not need to fill out all the fields.

If the user is not required to fill out ALL the fields, then the addition does not work because there’s one field missing. So it returns NaN.

Is there a smart way to have a sum operate correctly even if one of the addition fields is not filled out?

I want to order a coffee for $2 with milk ($1). It should cost $3.
There’s an option of making it a large size for $2 more, but I don’t want the larger size.

Now the “extra size” field in the sum is empty, so when adding to $3, it will return an error. → How would you recommend solving it?

thank you

Hi @axme ,

Have all numbers field required in calculation to be in collection with default 0 and update them if a selection is made,

or you could go an extra mile to have booleans as companions in order to check if the numbers field is necessary for calculation in conditional.

For example,
in collection will have numbers field as follows
normal $2
large $4
milk $1

if milk is true, update price with normal+milk

but this requires multiple update actions.


I’m curious, how do you have the database set up for your products and add-ons? There may be an even easier solution to this. I would just need to know how you have it configured. Screenshots could help too.

Hi @axme,

Ok, I found the workaround - though quite bizarre, but it worked for me :slight_smile:

If I understood the problem correctly: when one of the dropdowns isn’t selected - it has no value, and the whole formula stops working.

Here is what I did:

  • add an input box for each dropdown (I did it on a same screen but I assume it’ll be better to create a separate screen for that)

  • for each input, set a default value, taken from the corresponding dropdown:

    In my case, the collection is called Option1 and the price is Price.

  • for the total price in the DB Create/Update action, sum up the values from the inputs:
    Screenshot 2022-04-01 at 15.34.17

  • See if it works for you :slight_smile:

How does this work for me: after I change the dropdown, values in inputs are changed immediately. Upon pressing update the price is calculated correctly, even if one or several dropdowns are unselected.

Given the fact that Adalo can change the behaviour quickly, including setting default values for the variables and inputs, I have no idea for how long will this workaround work :slight_smile: But now it could be an option.



Thank you so much @Victor, your solution worked!
And another big thank you for the careful explanation of each step!

I don’t know how you came up with this idea for solving it, but you blew my mind :smiley:

Have a nice weekend,

1 Like