• Resolved damniano

    (@damniano)


    Hello,
    is it possible to create multiple “IF” statements in a formula?

    Let’s assume that I have fields A, B, C, and D (I actually have 10 such fields).
    If A is checked then (A * 2 + 35)
    If B is checked then (B / 2 + 15)
    C = quantity = if C is > 0 then (value for C + D/1000*15)

    Finally, the sum of A, B, C is:
    IF {A} {(A * 2 + 35)} + IF {B} {(B / 2 + 15)} + IF {C} {(D + E/1000*15)}

    For now, I can’t calculate it because, for example, the formula IF {A} {(A * 2 + 35)} gives me 35 (because it is +35) even though the field is not selected.

    • This topic was modified 8 months, 4 weeks ago by damniano.
    • This topic was modified 8 months, 4 weeks ago by damniano.
    • This topic was modified 8 months, 4 weeks ago by damniano.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support TomStylemixThemes

    (@tomstylemixthemes)

    Hi @damniano,
    Thanks for reaching out to us!

    From the results you’re getting, it looks like the option values are not being calculated. Please check the element where your options are stored — make sure that the option values are enabled for calculation: https://prnt.sc/Rf96icj7E-lz

    It’s also recommended to reference the element by its value in the formula. For example:
    IF(P==10){ }
    Here, P is the short name of the field where all options are listed, and 10 is the value of option A.

    I hope this helps resolve the issue!

    Kind regards

    Thread Starter damniano

    (@damniano)

    Hi @tomstylemixthemes

    I’m sure that the option values are enabled for calculation.

    But: If A is selected then (A * 2 + 35) – it works. But if I unselected A, I still have 35 left, because 0 * 2 + 35 equals 35. And I need 0 then, because A is unselected – that’s why I need an IF condition.

    Then I have for example C field (quantity field). I need count: (15 per C + D/1000*15) but only if C is greater than 0. That’s why I need a second IF condition.

    Finally, I need the sum of all these fields (and I have 10 of them). Which means that I need the sum of all IF conditions.

    I don’t know if I’ve described it well. Do you understand me?

    A – base plate field.
    C – Gusset Field
    D – other quantity field at the top of my form.

    • This reply was modified 8 months, 3 weeks ago by damniano.
    • This reply was modified 8 months, 3 weeks ago by damniano.
    • This reply was modified 8 months, 3 weeks ago by damniano.
    • This reply was modified 8 months, 3 weeks ago by damniano.
    Plugin Support juliastylemixthemes

    (@juliastylemixthemes)

    Hi @damniano,

    Thanks for explaining clearly — this is a common question. The Cost Calculator Builder does support combining multiple IF conditions in formulas, but you have to ensure a few important details are set correctly for them to behave as expected.

    What to double-check:

    1. Option values are enabled and set properly
      Each checkbox/dropdown field you use with IF needs to have value(s) assigned. If a field has no value, or uses labels only, the IF test can default to 0 (or behave unexpectedly). You seemed to have confirmed values are enabled, which is great.
    2. Zero or default behavior for unselected fields
      If an option is unchecked, its value is often treated as 0. So an expression like IF(A){(A*2+35)} will still evaluate as 35 if “A” is 0 (because (0 * 2 + 35) = 35). To avoid that, you should explicitly check IF(A > 0){…} rather than just IF(A){…}.
    3. Sum of IFs
      To sum multiple conditional expressions, you can do something like this: IF(A > 0){(A * 2 + 35)} + IF(B > 0){(B / 2 + 15)} + IF(C > 0){( D + E/1000*15 )}. So each IF(...) is independent, returning 0 when the condition isn’t met. Then the sum adds up only the active conditions.

    If you apply those checks (especially changing your IF(A){…} to IF(A > 0){…}), you should get the behavior you want: fields contributing only when selected or when quantity is above zero, and summing them cleanly.

    Cheers

    Thread Starter damniano

    (@damniano)

    Hi, @juliastylemixthemes

    To sum multiple conditional expressions, you can do something like this: IF(A > 0){(A * 2 + 35)} + IF(B > 0){(B / 2 + 15)} + IF(C > 0){( D + E/1000*15 )}. So each IF(...) is independent, returning 0 when the condition isn’t met. Then the sum adds up only the active conditions.

    But it doesn’t work, or am I doing something wrong?

    If I enter the formula: IF(CL>0){CL *2.1+35} + IF(CM>0){CM} an error appears: “An error expression found, please fix it”.

    Each of these formulas works correctly separately, but when used together with the “+” sign, there is an error.

    • This reply was modified 8 months, 2 weeks ago by damniano.
    Thread Starter damniano

    (@damniano)

    Okay, the above doesn’t seem to work, but I found a solution using this:

    https://ww.wp.xz.cn/support/topic/sum-of-conditional-formulas-in-a-formula/

    I created several formulas, then the last one with the highest ID, and added up the previous ones.

    Hi @damniano ,

    We are glad to hear that, you were able to find a solution.
    We appreciate your cooperation with us and hope it will last for long.

    If you ever need help refining the formulas or if anything else comes up, feel free to reach out. We’re always here to help!

    Best regards,

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Multiple “IF” in Formula’ is closed to new replies.