Comments

3 comments

  • Rich Albrecht

    I have to have a calculation that shows the percentage of how many board members selected "Approved" in a category.

     

    So if 6 were approved it would fall to the line (total / 12) * 100 which would be 6/12 * 100 = 50.

     

    It always shows 100????

    var total;
    total = 0;
    if (@President - Annual Report = "Approved") {
    total = total + 1;}
    if (@VP Techical - Annual Report = "Approved") {
    total = total + 1;}
    if (@VP Membership - Annual Report = "Approved") {
    total = total + 1;}
    if (@VP Legislative - Annual Report = "Approved") {
    total = total + 1;}
    if (@VP Education - Annual Report = "Approved") {
    total = total + 1;}
    if (@VP Affiliate - Annual Report = "Approved") {
    total = total + 1;}
    if (@Treasurer - Annual Report = "Approved") {
    total = total + 1;}
    if (@Region 1 - Annual Report = "Approved") {
    total = total + 1;}
    if (@Region 2 - Treasure’s Report - = "Approved") {
    total = total + 1;}
    if (@Region 3 - Treasure’s Report - = "Approved") {
    total = total + 1;}
    if (@Region 4 - Annual Report = "Approved") {
    total = total + 1;}
    if (@Region 5 - Annual Report = "Approved") {
    total = total + 1;}
    if (total === 0) {
    0;} else {
    (total / 12) * 100;}

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Rich,

    for comparison you need double equal signs: == "Approved".

    try at the end 

    if (total === 0) {
    0;} } ;
    total == 0 ? 0 : (total / 12) * 100;

    or:

    var arrBoard = [@president,@VP Techical,@VP Membership, etc]
    var total = arrBoard.filter(function(value){
    return value === "Approved";
    }).length;
    total == 0 ? 0 : (total / 12) * 100;

    Rainer
    rg@delos-consulting.com

     

    0
    Comment actions Permalink
  • Marc Høegh

    Hi Rich,

    What you're trying to achieve can be done by collecting all reports in an array and then filtering by whether or not they have the value 'Approved'. E.g.:

    var reports = [
    @President - Annual Report,
    @VP Techical - Annual Report,
    @VP Membership - Annual Report,
    @VP Legislative - Annual Report,
    @VP Education - Annual Report,
    @VP Affiliate - Annual Report,
    @Treasurer - Annual Report,
    @Region 1 - Annual Report,
    @Region 2 - Treasure’ s Report -,
    @Region 3 - Treasure’ s Report -,
    @Region 4 - Annual Report,
    @Region 5 - Annual Report
    ];

    var total = reports.filter(function(report) {
    return report === 'Approved';
    }).length;

    total && (total / 12) * 100;

    In the last line, total is returned if it is zero, otherwise the code after "&&" will execute. No need for conditionals.

    In terms of the code you've shared; note that you are using single equal signs in your if-statements. This means that you are assigning a value, not comparing values. For this you need the double or (for strict comparison) the triple equal signs operator, just as you have in the last statement in your code.

    Hope this helps.

    Marc

    1
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk