• Resolved minimega

    (@minimega)


    Hello!

    I am building a body shape calculator using the “Calculated Field Forms” Plugin and I need help getting the formula to work in Javascript. I have the formula working in Excel, but I need help with the conversion.

    Here is the Excel formula. I’ve tested this and it works:

    B1 = Bust Measurement
    B2 = Waist Measurement
    B3 = Hip Measurement
    B4 = High Hip Measurement

    Individual formulas:

    =IF(AND(((B1-B3)<=1),((B3-B1)<3.6),((B1-B2)>=9)), “Hourglass”, “False”)
    =IF(AND(((B3-B1)>=3.6),((B3-B1)<10),((B3-B2)>=9),((B4/B2)<1.193)), “Bottom Hourglass”, “False”)
    =IF(AND(((B1-B3)>1),((B1-B3)<10),((B1-B2)>=9)), “Top Hourglass”, “False”)
    =IF(AND(((B3-B1)>2),((B3-B2)>=7),((B4/B2)>=1.193)), “Spoon”, “False”)
    =IF(AND(((B3-B1)>=3.6),((B3-B2)<9)), “Triangle”, “False”)
    =IF(AND(((B1-B3)>=3.6),((B1-B2)<9)), “Inverted Triangle”, “False”)
    =IF(AND(((B3-B1)<3.6),((B1-B3)<3.6),((B1-B2)<10)), “Rectangle”, “False”)

    Combined into one formula:

    =IF(AND(((B1-B3)<=1),((B3-B1)<3.6),((B1-B2)>=9)), “Hourglass”, IF(AND(((B3-B1)>=3.6),((B3-B1)<10),((B3-B2)>=9),((B4/B2)<1.193)), “Bottom Hourglass”, IF(AND(((B1-B3)>1),((B1-B3)<10),((B1-B2)>=9)), “Top Hourglass”, IF(AND(((B3-B1)>2),((B3-B2)>=7),((B4/B2)>=1.193)), “Spoon”, IF(AND(((B3-B1)>=3.6),((B3-B2)<9)), “Triangle”, IF(AND(((B1-B3)>=3.6),((B1-B2)<9)), “Inverted Triangle”, IF(AND(((B3-B1)<3.6),((B1-B3)<3.6),((B1-B2)<10)), “Rectangle”)))))))

    Here it is converted to reference “fieldname” for the plugin instead of the Excel cell reference:

    =IF(AND(((fieldname1- fieldname3)<=1),(( fieldname3- fieldname1)<3.6),(( fieldname1- fieldname2))>=9)), Hourglass, IF(AND(((fieldname3- fieldname1)>=3.6),(( fieldname3- fieldname1)<10),(( fieldname3- fieldname2)>=9),(( fieldname5/ fieldname2)<1.193)), Bottom Hourglass, IF(AND(((fieldname1- fieldname3)>1),(( fieldname1- fieldname3)<10),(( fieldname1- fieldname2)>=9)), Top Hourglass, IF(AND(((fieldname3- fieldname1)>2),(( fieldname3- fieldname2)>=7),(( fieldname5/ fieldname2)>=1.193)), Spoon, IF(AND(((fieldname3- fieldname1)>=3.6),(( fieldname3- fieldname2)<9)), Triangle, IF(AND(((fieldname1- fieldname3)>=3.6),(( fieldname1- fieldname2)<9)), Inverted Triangle, IF(AND(((fieldname3- fieldname1)<3.6),(( fieldname1- fieldname3)<3.6),(( fieldname1- fieldname2)<10)), Rectangle)))))))

    Based on my javascript research, I need nested if and if else statements. Here’s what I have. The most common body shape is on the top and the least common body shape is on the bottom. What am I doing wrong and how do I get this to work?

    if (&& (((fieldname3-fieldname1)<3.6),((fieldname1-fieldname3)<3.6),((fieldname1-fieldname2)<10)) {
    fieldname 4 = (‘Rectangle’);
    } else if (&& (((fieldname3-fieldname1)>=3.6),((fieldname3-fieldname1)<10),((fieldname3-fieldname2)>=9),((fieldname5/fieldname2)<1.193)) {
    fieldname4 = (‘Bottom Hourglass’);
    } else if (&& (((fieldname1-fieldname3)>1),((fieldname1-fieldname3)<10),((fieldname1-fieldname2)>=9)) {
    fieldname4 = (‘Top Hourglass’);
    } else if (&& (((fieldname3-fieldname1)>2),((fieldname3-fieldname2)>=7),((fieldname5/fieldname2)>=1.193)) {
    fieldname 4 = (‘Spoon’);
    } else if (&& (((fieldname3-fieldname1)>=3.6),((fieldname3-fieldname2)<9)) {
    fieldname4 = (‘Triangle’);
    } else if (&& (((fieldname1-fieldname3)>=3.6),((fieldname1-fieldname2)<9)) {
    fieldname4 = (‘Inverted Triangle’);
    } else (&& (((fieldname1-fieldname3)<=1),((fieldname3-fieldname1)<3.6),((fieldname1-fieldname2))>=9)) {
    fieldname4 = (‘Hourglass’);
    }

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @minimega

    My apologies for the delay in responding to your question. I did not receive the forum notification about your entry.

    Javascript is a case-sensitive language. Please, do not confuse the IF operation in the plugin with the Javascript if conditional statement.

    Your equation includes some parser errors. The Excel formula and the equation in our plugin are similar, but they have some differences.

    – You must remove the equal symbol from the beginning.
    – The texts must be enclosed between single or double-quotes.
    – The last IF operation is unnecessary.
    – And please, be careful with the number of parentheses.

    The correct equation would be:

    IF(AND(fieldname1-fieldname3<=1, fieldname3-fieldname1<3.6, fieldname1-fieldname2>=9), 'Hourglass', IF(AND(fieldname3-fieldname1>=3.6, fieldname3-fieldname1<10, fieldname3-fieldname2>=9, fieldname5/fieldname2<1.193), 'Bottom Hourglass', IF(AND(fieldname1-fieldname3>1, fieldname1-fieldname3<10, fieldname1- fieldname2>=9), 'Top Hourglass', IF(AND(fieldname3-fieldname1>2, fieldname3-fieldname2>=7, fieldname5/fieldname2>=1.193), 'Spoon', IF(AND(fieldname3-fieldname1>=3.6, fieldname3-fieldname2<9), 'Triangle', IF(AND(fieldname1-fieldname3>=3.6, fieldname1-fieldname2<9), 'Inverted Triangle', 'Rectangle'))))))

    Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Converting Nested If AND Excel formula to Javascript’ is closed to new replies.