0

I want to calculate pricing based on location, destination & weight.

For example, if a user wants to send a shipment from Austria to Ireland and the weight is up to 10 kg then the price will be $27 and if up to 20 kg then $29 and so on up to 50 kg.

I have From & To fields for location & destination and I have a repeating section which includes a weight field and at the end I have a calculation field.

How can I achieve this?

1 Answer 1

1

There are two ways to write conditional if/then calculations in Cognito Forms.

  1. if <condition> then <true result> else <false result>
  2. <condition> ? <true result> : <false result>

For your specific example, lets assume you create a calculation outside your repeating section called Total Weight with the calculation =Packages.Sum(Weight) that sums up the weight of the items in the Packages repeating section.

You can then write the following calculation to based on your example:

=if Location = "Austria" and Destination = "Ireland" then if Weight <= 10 then $27 else if Weight < 20 then $29 else ... else ...

If you have a ton of options like this, I suspect this would be very difficult to work through. It sounds like you want to be able to look up a value from a very long table of potential values. Please provide feedback to this answer and I will be glad to refine my response.

5
  • Yes we need to set prices based on country to country, how did you end the calculation with else ... else ... form is not accepting that.
    – Usman
    Commented Oct 29, 2015 at 14:17
  • The ... was just placeholder for additional logic you may need to write for additional countries and weights. How many different configurations do you expect? Commented Oct 29, 2015 at 15:57
  • I see, how do i end the logic as it is asking for else at the end, we need same configuration for up to 20 countries and weights are up to 10,20,30,40 & 50kg
    – Usman
    Commented Oct 29, 2015 at 16:23
  • You have to have an else value, so just make the value really big if you do not expect the else to ever be used. Commented Oct 29, 2015 at 16:31
  • I can't seem to figure out how to end the statement, it keep asking me to add else at the end, i tried different options but it doesn't work, can you give me a complete calculation please so i can add more countries, thanks.
    – Usman
    Commented Oct 30, 2015 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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