• Resolved Graicifyd

    (@graicifyd)


    Hi,

    Thank you so much for an amazing plugin.

    How can I sum up a range of fields, for example:

    Field A(200 – 300)
    Field B(100 – 100)

    Calculated (200 + 100) – (200 + 100)

    Thanks in advance.

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

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @graicifyd

    The URL provided (https://www.ecommercenext.org/calculator-2) generates a 404 Error Page not found.

    Best regards.

    Thread Starter Graicifyd

    (@graicifyd)

    I am sorry about that, this is it:

    • This reply was modified 4 years, 10 months ago by Graicifyd.
    Plugin Author codepeople

    (@codepeople)

    Hello @graicifyd,

    Assuming the fields are: fieldname1, fieldname2 (the fields’ names are hypothetical, you should to use the names of the fields in your form), insert a calculated field with the equation:

    
    (function(){
    var a = fieldname1.split('-'), b = fieldname2.split('-');
    return CONCATENATE(SUM(a[0].trim(),b[0].trim()),'-',SUM(a[1].trim(),b[1].trim()));
    })()
    

    and that’s all.
    Best regards.

    Thread Starter Graicifyd

    (@graicifyd)

    Thanks for your support. It’s not working yet, I guess I got something wrong.

    See the first field below.

    Field 1

    Second file here.

    Field 2

    The calculation I used.

    Calculated Field

    The final output

    Output or live link.

    There was no calculation in the form at all. Please help, thank you in advance.

    Plugin Author codepeople

    (@codepeople)

    Hello @graicifyd

    Your original description is not for checkboxes, because the checkbox fields allow multiple choices selection, and your initial description has not sense in this context.

    Best regards.

    Thread Starter Graicifyd

    (@graicifyd)

    Okay how can I make this work? Or can checkboxes not work in this context?

    Plugin Author codepeople

    (@codepeople)

    Hello @graicifyd

    You have described the sum of two fields, but in the checkbox fields, how you want to proceed if were ticked multiple choices? I cannot respond to this question for you.

    Best regards.

    Thread Starter Graicifyd

    (@graicifyd)

    Thanks for your support. What I intend to do is to sum up the the lower values and the upper values. If in field 1, two options are selected

    Option a (100 – 200)
    Option b (300 – 400)

    and in field 2, two options are selected.

    Option a(150 – 400)
    Option b(500- 600)

    I want to sum up the lower values(100 + 300 + 150 + 500) – higher values (200 + 400 + 400 + 600)

    Is this possible?

    Plugin Author codepeople

    (@codepeople)

    Hello @graicifyd

    In this case the equation should be implemented as follows:

    
    (function(){
        var a = fieldname1|r, 
            b = fieldname2|r, 
            r1 = 0, 
            r2 = 0;
    
        for(var i in a)
        {
            r1 = SUM(r1, a[i].split('-')[0].trim());
            r2 = SUM(r2, a[i].split('-')[1].trim());
        }
        
        for(var i in b)
        {
            r1 = SUM(r1, b[i].split('-')[0].trim());
            r2 = SUM(r2, b[i].split('-')[1].trim());
        } 
    
        return CONCATENATE(r1, '-', r2);
    })()
    

    Please, note the support service does not cover the implementation of the users’ projects (forms or formulas). If you need additional help implementing your equations, we can offer you a custom coding service through our private website: Customization

    Best regards.

    Thread Starter Graicifyd

    (@graicifyd)

    This is amazing, thank you. You are the best.

    Thread Starter Graicifyd

    (@graicifyd)

    Thank you for this. This code

    (function(){
    var a = fieldname1.split('-'), b = fieldname2.split('-');
    return CONCATENATE(SUM(a[0].trim(),b[0].trim()),'-',SUM(a[1].trim(),b[1].trim()));
    })()

    worked perfectly to sum two dropdown data, what if I want to sum up to 7 fields instead of two can I still use the same code?

    Thank you for your support.

    See page here.

    Plugin Author codepeople

    (@codepeople)

    Hello @graicifyd,

    The solution depends on data. If the fields you want sum are DropDown fields with range structures, yes you can use the same logic.

    
    (function(){
        var a = fieldname1.split('-'), 
            b = fieldname2.split('-'),
            c = fieldname3.split('-'),
            d = fieldname4.split('-');
    
        return CONCATENATE(SUM(a[0].trim(),b[0].trim(),c[0].trim(),d[0].trim()),'-',SUM(a[1].trim(),b[1].trim(),c[1].trim(),d[1].trim()));
    })()
    

    – or even better –

    
    (function(){
        var l = [fieldname1, fieldname2, fieldname3, fieldname4], r1 = 0, r2 = 0;
        
        for(var i in l)
        {
           r1 = SUM(l[i].split('-')[0].trim(),r1);
           r2 = SUM(l[i].split('-')[1].trim(),r2);
        } 
        return CONCATENATE(r1,'-',r2);
    })()
    

    With the second alternatives you can increase the number of dropdown fields in the list l and you don’t need to edit the rest of the equation, or create a different variable per field.

    Best regards.

    Thread Starter Graicifyd

    (@graicifyd)

    Thank you so much for this, it worked perfectly.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘SUM UP A RANGE OF FIGURES’ is closed to new replies.