Form Calculation widget: I need help with a complex conditional statement

  • SmootMiddleton
    Asked on April 16, 2025 at 12:25 PM

    I'm trying to do a complex calculation. How do I determine which of five numeric fields is the largest value: score1, score2, score3, score4, score5?

  • Jefferson JotForm Support
    Replied on April 16, 2025 at 1:19 PM

    Hi Teresa,

    Thanks for reaching out to Jotform Support. You can identify the largest value among your five numeric fields by using the max() function inside a Form Calculation widget. Let me show you how:

    1. In Form Builder, click on the Add Element on the left side of the page.Form Calculation widget: I need help with a complex conditional statement Image 1 Screenshot 60
    2. Click on the Widgets tab.
    3. Add a Form Calculation widget to your form and rename it as Largest Value.Form Calculation widget: I need help with a complex conditional statement Image 2 Screenshot 71
    4. Click on the wand icon to open the Form Calculation Widget window.Form Calculation widget: I need help with a complex conditional statement Image 3 Screenshot 82
    5. In the Form Calculation Widget window, copy the formula in the screenshot.
    6. Click on the Save button.Form Calculation widget: I need help with a complex conditional statement Image 4 Screenshot 93

    Here's the sample output:

    Form Calculation widget: I need help with a complex conditional statement Image 5 Screenshot 104

    Give it a try and reach out again if you have any other questions.

  • SmootMiddleton
    Replied on April 16, 2025 at 3:00 PM
    Can I put a string in instead of the numeric value? In other words, if I
    just copy the value I've lost which score was the highest. I need to know
    which score was the highest so passing a string like "ScoreAwareness"
    rather than the value is best.
    ...
  • Ronald JotForm Support
    Replied on April 16, 2025 at 4:15 PM

    Hi Teresa,

    After following the guide Jefferson shared earlier, you can add Conditional Logic to your form to determine which score had the highest value. Let me show you how to set it up:

    1. On your My Forms page, hover your mouse over your form and click on Edit Form.

    2. In Form Builder, click on the Add Form Element menu and drag-drop a Short Text field to your form.

    3. Click on the Type a Question text and change it to the question you want to use.

    Form Calculation widget: I need help with a complex conditional statement Image 1 Screenshot 60

    Now, let's set up the conditions:

    1. In Form Builder, in the orange navigation bar at the top of the page, click on Settings.

    2. Click on Conditions on the left of the page.

    3. Now, click on Add a New Condition and then click on Update/Calculate Field.

    Form Calculation widget: I need help with a complex conditional statement Image 2 Screenshot 71

    4. Set the conditions like you see below:

    Form Calculation widget: I need help with a complex conditional statement Image 3 Screenshot 82

    Form Calculation widget: I need help with a complex conditional statement Image 4 Screenshot 93

    You can clone and test my demo form here. Set up Conditions for all of the choices for your question. Check out the screencast below to see how your form will work after setting up the Conditions:

    Form Calculation widget: I need help with a complex conditional statement Image 5 Screenshot 104

    Give it a try and let us know how it goes.

  • SmootMiddleton
    Replied on April 16, 2025 at 5:21 PM

    The maximum number function didn't work for me. I got ,#,#,#, in the largest score field. Did I need to keep the previous conditional logic of ensuring the initial values were not zero?

  • SmootMiddleton
    Replied on April 16, 2025 at 6:05 PM
    I added the max() function code and got several values and commas in the
    highest score field. Is this because the fields are being calculated. Do I
    need to allow time for the fields to be completely calculated before doing
    another calculation with the fields?
    Also, I have a default value sequence if there is a tie, Connection,
    Alignment, Awareness, Momentum, Participation. Where should I add this
    logic?
    ...
  • Lorenz JotForm Support
    Replied on April 16, 2025 at 9:32 PM

    Hi Teresa,

    I checked your form 250928077890165, it doesn't seem like you've applied the solution my colleague suggested. You did mention that you get several values and commas in the highest score field, could you try adding the calculation again so we can check what's wrong? I would suggest you clone our demo form 251055999110963 to your account, to further inspect how the calculations and condition were set up.

    As for the the case where there's a tie, can you explain a bit more what exactly should happen in case there's a tie, so we can come up with a better solution.

    Once we hear back from you, we'll be able to help you with this.

  • SmootMiddleton
    Replied on April 16, 2025 at 10:40 PM
    I don't understand how to clone the first response. The field that is
    related to the multiple responses is the HighestScore field. It has the
    calculations in it.
    If all the scores or several scores are the same. Then whichever score type
    is listed first in the list is taken as the desired value. For example,
    Teams tend to unlock growth faster when connection or alignment is strong.
    So the most desirable score type is list first on the priority list, e.g.,
    Connection then Alignment, then Awareness, then Participation followed by
    Momentum.
    So if ScoreAlignment = 6.5 and ScoreParticipation = 6.5 refer to the
    priority list. In this case, ScoreAlignment would be the default to pass
    into the PillarStrength field.
    Let me know if that makes sense.
    Thank you.
    ...
  • Raymond JotForm Support
    Replied on April 17, 2025 at 4:16 AM

    Hi Teresa,

    I checked your form and see that the Form Calculation widget for the Highest Score and Lowest score is incorrectly configured. The comma within the functions must be marked as a number (black), for it to work as expected. Let me show you how to do that:

    1. In Form Builder, click on the Highest Score field, and on the Wand icon next to it.
    2. In its settings on the right, click on the gray comma to turn them to black.
    3. Click on the Save button.
    4. Repeat the same for the LowestScore field and that's it.
      Form Calculation widget: I need help with a complex conditional statement Image 1 Screenshot 30

    Here's how it would work:

    Form Calculation widget: I need help with a complex conditional statement Image 2 Screenshot 41

    By default, the results that are first in the list are listed if there are same scores in two categories.

    Give it a try and let us know if you need any help.

  • SmootMiddleton
    Replied on April 17, 2025 at 8:10 AM
    Thank you. This has been very helpful. Everything is nearly working
    perfectly. The one challenge I'm having currently is when I set all the
    scores at an equal value the Awareness Score is set as the highest value.
    Based on the order in the max () function and the order of conditional if
    statements the Connection Score should be identified as the highest value.
    I need help with this issue.
    The final parts of this quiz is to populate the Thank You page with one of
    20 profiles possible or do you think it's best to create an email with this
    simple information rather than create 20 Thank You pages.

    And second, send the user name, email and team profile name to Kit
    (formally Convertkit) for email marketing sequences.

    Thank you for your assistance.
    ...
  • Jessica JotForm Support
    Replied on April 17, 2025 at 8:53 AM

    Hi SmootMiddleton,

    Thanks for reaching out to Jotform Support. We’ll need a bit of time to look into this. We'll get back to you as soon as we can.

    We appreciate your patience and understanding in this.

  • SmootMiddleton
    Replied on April 17, 2025 at 9:45 AM
    Thank you.
    ...
  • Jessica JotForm Support
    Replied on April 18, 2025 at 4:42 AM

    Hi SmootMiddleton,

    I have cloned your form to check on how the configuration is presently made, and see that you are referring to the field ScoreAwareness and ScoreConnection. Are you referring to that you would like the form to judge which from the two field have the highest value, then take that the score of the field with highest value, or are you referring to something else?

    If this is the case, you can consider subtract ScoreAwareness with ScoreConnection, then depending on whether the value is positive or negative, you can add an additional Short Text field and conditional logic to copy that field. If this is not what you are referring to, could you elaborate more with us?

    About your other questions, to avoid confusion, we'll help you in separate threads. You can refer to the following threads, we'll help you there soon:

    Let us know if you need more help.

  • mjoe30
    Replied on April 19, 2025 at 1:03 AM

    To find the largest value among five scores, you can use the Math.max() function, like this:

    let largestScore = Math.max(score1, score2, score3, score4, score5);

    This will return the highest value from the five scores. If you need to implement it in a conditional structure, you can use if statements to compare each score

    Name: Mr Joe

    Founder:

Your Answer