Sum of column based on another Column
Sum of column based on another Column

I want to see sum of a column based on another column value:
var ftdA = rows
.data()
.pluck(7)
.reduce( function (a, b) {
if (a == "FTD" || b == "FTD") {
var ftda2 = rows
.data()
.pluck(6)
.reduce( function (a, b) {
var ftda3 = a + b*1;
return ftda3;
}, 0);
ftda = ftda2.toFixed(2);
}
return ftda;
}, 0);
I used something like this but is not working still sum all the values on that column.
Mind you I use RowGroup
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
In order to understand the data you have and what you want to accomplish please build a simple test case representing your data and the RowGroup. This way we can work with your data to help you achieve the desired result.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
This is the live test as you can see the number of System Architect's are showing up but I want their sum of age
http://live.datatables.net/zezuxali/2/
Thanks for the test case. I can see that
ftdN
results in0
andftdA
results in a value. Please provide details of where the problem is and what you are expecting. The more details you provide the easier it will be for us to help.Kevin
I changed the test case please look at it again it should only show the total age of the system architects
Looks like we cross posted
I don't think
reduce()
is going to work for what you want. I thinkrows().every()
is a good choice. Updated your example here:http://live.datatables.net/zezuxali/4/edit
Loops through all the rows in the RowGroup and increments the
ftdA
variable by the age of each System Architect.Kevin
Wooow nice Kevin that was an awesome approach