2

In our project we need to use the Sumproduct Function (Similar to Excel SUMPRODUCT function).

How do I implement it using Apex class.

Thanks in advance!

Cheers!

1 Answer 1

0

Here is the sample code, this will give an Idea to implement.

Integer total = 0;
//Take two maps expecting you need to product 2 columns
//Column 1 and 2 can be integer or any of the valid data type
// put your values into the maps by looping through your values
//Assuming you are ready with the maps data
Map<Id, Column1>  map1= new Map<Id, column1>();
Map<Id, Column2>  map1= new Map<Id, column2>();

for(id i: map1.keySet()){

    if(map2.containsKey(i)){
           integer prod = o; 
           prod = (map1.get(i) * map2.get(i));
           total = total +prod; 
     }
}
//This is so genreral idea just serves as tip to start your code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .