Expand my Community achievements bar.

Conditional Sum of Table by categories?

Avatar

Level 2

Hi, This is a continuation of an earlier question, I thought I'd start fresh because I partially figured out how to do a part of this, through help from this site. Thanks to all.

Anyway, I have two tables in two separate subforms. (which is needed for various reasons.) a DetailsTable and a SummaryTable.

The summary table is supposed to summarize the values of the BudgetCost field from the DetailsTable. In total, there are six categories, and I have figured out that when placed on the exit event of the BudgetCost field, the following code works to populate the NumericField5, which represents the sum of the details cost if the first drop down is selected. (ie "Maintenance" or raw value of "1".

// Getting the count of number of rows repeated

var numberOfRows = DetailTableSubform.DetailsTable.DetailRow.instanceManager.count;

//final total initialization

var total = 0;

for (var i=0; i<numberOfRows; i++){

// checking category is selected or not

          if( xfa.resolveNode("DetailTableSubform.DetailsTable.DetailRow["+i+"].DropDownList1") != null &&               xfa.resolveNode("DetailTableSubform.DetailsTable.DetailRow["+i+"].DropDownList1").rawValue != null  ){

// getting the category values

          var categoryValue = xfa.resolveNode("DetailTableSubform.DetailsTable.DetailRow["+i+"].DropDownList1").rawValue;

// Matching the category values with "Maintenance"

          if (categoryValue == "1"){

// Summing the total based on the "A" Category

               total += xfa.resolveNode("DetailTableSubform.DetailsTable.DetailRow[" + i + "].BudgetCost").rawValue;
               this.resolveNode("HeaderSubform.SummaryTable.Row1.NumericField5").rawValue = total
         }

     }

}

The above code works beautifully! However, I can only get the summaries of the DetailsTable values for only the rows (which is expanding or repeating by the way) where the dropdown1 value is 1 or "Maintenance".

How can I change this to apply the next 5 other possible categories?

I would like to say that the summary should sum all of the categories in their own separate numericfield(5 through 9), based on the selections in the dropdownlist1. numericfield 5 = sum of all budget cost where "maintenance is selected, NumericField6 = Sum of all budget cost where "patrol" is selected and so on.

I have tried adding "else if" statements after the this.resolveNode ("~...") above, but cant get it to work at all, perhaps there is a different approach that I needed to try.

I have also tried placing a similiar code in the calculate event of each NumericField in the summary table, but that does nothing at all.

Please help! and thank you!!!

J

0 Replies