• Resolved superky

    (@superky)


    Hi codepeople,

    I would like to make a total of the best 5, but the equation below is not working for me
    SUM(MAX(fieldname3,fieldname4,fieldname6,fieldname5,fieldname16,fieldname18,fieldname20,fieldname22,5)).

    Can you please assist me on how to get the best 5 ?

    Thank you

Viewing 6 replies - 16 through 21 (of 21 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @superky

    There are many alternatives. You can use conditional statements to check every field, one by one, or emulate an array and use the filter method.

    For example, assuming you have three fields, fieldname1, fieldname2, and fieldname3, and you want to know the number of fields whose values are 8 or 9 (the fields’ names and values are hypothetical)

    The equation can be implemented as follows:

    (function(){
    var n = 0;
    if(OR(fieldname1==8, fieldname1==9)) n = n+1;
    if(OR(fieldname2==8, fieldname2==9)) n = n+1;
    if(OR(fieldname3==8, fieldname3==9)) n = n+1;
    
    return n;
    })()

    Now, you can implement the same equation by emulating an array and use its filter method as follows:

    [fieldname1, fieldname2, fieldname3].filter( v => OR(v==8,v==9)).length;

    Best regards.

    Thread Starter superky

    (@superky)

    Sorry, still cant get it worked.

    Let me explain it again in another way, forget the previous requirements mentioned above:

    So there are 4 fields(fieldname1,fieldname2,fieldname3,fieldname4), each fields are a dropdown with a list of subjects,
    Maths1, Maths2, Chemistry, Music, Economies, History, Physics, Literature, Biology etc.

    Each of the 4 fields(fieldname1,fieldname2,fieldname3,fieldname4), has a field to enter their marks(fieldname5,fieldname6,fieldname7,fieldname8).
    (fieldname5 is to fieldname1, fieldname6 is to fieldname2, etc)

    Now I need to calculate them with the 5 highest marks, including 1.5*best of Maths1/Maths2/Chemistry/Economies/Physics, while others multiply by 1.

    Plugin Author codepeople

    (@codepeople)

    Hello @superky

    I’m sorry, but I don’t understand your description. You’ve referred to four dropdown fields with four associated fields for entering the marks. But in the maths description, you are talking about the five highest marks (but there are only four fields for entering the marks). I would need you to describe a specific use case.

    Best regards.

    Thread Starter superky

    (@superky)

    ok, my bad. I overlooked it.

    This is an admission score calculator. There are Core Subjects and Electives

    Core Subjects – Fixed

    • English
    • Chinese Language
    • Mathematices – Compulsory
    • Liberal Studies
    • Electives – Dropdown list

    • Maths1
    • Maths2
    • Chemistry
    • Music
    • Economies
    • History
    • Physics
    • English Literature
    • Biology
    • Core Subjects has 4 associated fields (fieldname1,fieldname2,fieldname3,fieldname4) to enter the marks.

      Electives can choose 4 from the list
      4 dropdowns(fieldname5,fieldname6,fieldname7,fieldname8), 4 fields for marks (fieldname9,fieldname10,fieldname11,fieldname12).

      Now I need to calculate them with the 5 highest marks, including 1.5*best of Maths1/Maths2/Chemistry/Economies/Physics(only the highest among these subjects will be selected), while others remaining subjects (not including Maths1/Maths2/Chemistry/Economies/Physics) multiply by 1.

    Thread Starter superky

    (@superky)

    table += (function () {
    if (fieldname3 >= ‘3’ && fieldname4 >= ‘3’ && fieldname6 >=’3′ && fieldname5 >= ‘2’ ) return ‘<tr><td>’ + fieldname37 + ‘</td><td>’ + fieldname47 + ‘</td><td>’ + fieldname51 + ‘</td><td>’ +
    SUM([fieldname1, fieldname2, fieldname3, fieldname4, (function () {
    if (fieldname5 != ‘MTH1’ || fieldname5 != ‘MTH2’ || fieldname5 != ‘ECON’ || fieldname5 != ‘CHEM’ || fieldname5 != ‘PHYS’) return 1 * fieldname9;
    else {
    if (fieldname6 != ‘MTH1’ || fieldname6 != ‘MTH2’ || fieldname6 != ‘ECON’ || fieldname6 != ‘CHEM’ || fieldname6 != ‘PHYS’) return 1 * fieldname10;
    else {
    if (fieldname7 != ‘MTH1’ || fieldname7 != ‘MTH2’ || fieldname7 != ‘ECON’ || fieldname7 != ‘CHEM’ || fieldname7 != ‘PHYS’) return 1 * fieldname11;
    else {
    if (fieldname8 != ‘MTH1’ || fieldname8 != ‘MTH2’ || fieldname8 != ‘ECON’ || fieldname8 != ‘CHEM’ || fieldname8 != ‘PHYS’) return 1 * fieldname12;
    }
    }
    }
    })()].sort(function (a, b) { return a – b }).reverse().slice(0, 4),
    (function () {
    if (fieldname5 == ‘MTH1’ || fieldname5 == ‘MTH2’ || fieldname5 == ‘ECON’ || fieldname5 == ‘CHEM’ || fieldname5 == ‘PHYS’) return 1.5 * fieldname9;
    else {
    if (fieldname6 == ‘MTH1’ || fieldname6 == ‘MTH2’ || fieldname6 == ‘ECON’ || fieldname6 == ‘CHEM’ || fieldname6 == ‘PHYS’) return 1.5 * fieldname10;
    else {
    if (fieldname7 == ‘MTH1’ || fieldname7 == ‘MTH2’ || fieldname7 == ‘ECON’ || fieldname7 == ‘CHEM’ || fieldname7 == ‘PHYS’) return 1.5 * fieldname11;
    else {
    if (fieldname8 == ‘MTH1’ || fieldname8 == ‘MTH2’ || fieldname8 == ‘ECON’ || fieldname8 == ‘CHEM’ || fieldname8 == ‘PHYS’) return 1.5 * fieldname12;
    }
    }
    }
    })().sort(function (a, b) { return a – b }).reverse().slice(0, 1)) + ‘</td><td> 51 </td><td> 48.75 </td><td> 31 </td><td> 30 </td></tr>’; else return ”;
    })();

    Chem, phys,econ are the choice values.
    I have this code but this wouldnt work for me

    Plugin Author codepeople

    (@codepeople)

    Hello @superky

    I don’t understand your equation’s structure.

    If you want to sum the values:

    (1 or 1.5)*fieldname9+(1 or 1.5)*fieldname10+(1 or 1.5)*fieldname11+(1 or 1.5)*fieldname12

    The equation would be similar to:

    SUM(
        IF(IN(fieldname5|v, ['MTH1', 'MTH2', 'ECON', 'CHEM', 'PHYS']), 1.5, 1)*fieldname9,
        IF(IN(fieldname6|v, ['MTH1', 'MTH2', 'ECON', 'CHEM', 'PHYS']), 1.5, 1)*fieldname10,
        IF(IN(fieldname7|v, ['MTH1', 'MTH2', 'ECON', 'CHEM', 'PHYS']), 1.5, 1)*fieldname11,
        IF(IN(fieldname8|v, ['MTH1', 'MTH2', 'ECON', 'CHEM', 'PHYS']), 1.5, 1)*fieldname12
    )

    The use of modifier |v with the fields’ names of radio buttons, checkbox, and dropdown, gives you access to the information to be submitted by the field. In the fields fieldname5, fieldname6, fieldname7, and fieldname8, please, tick the “Choice text” option in the “Value to Submit” attribute.

    If you need someone that implements your project, please, contact us through the plugin website:

    https://cff.dwbooster.com/customization

    Best regards.

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘How to get the five highest value’ is closed to new replies.