io.github.geraldnguyen.excel.statistics.AverageIfs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of excel-formula Show documentation
Show all versions of excel-formula Show documentation
Implementation of popular excel formula in Java
The newest version!
package io.github.geraldnguyen.excel.statistics;
import io.github.geraldnguyen.excel.BaseIfs;
import io.github.geraldnguyen.excel.RangeCriteria;
import io.github.geraldnguyen.excel.math.SumIfs;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.List;
// https://support.microsoft.com/en-us/office/averageifs-function-48910c45-1fc0-4389-a028-f7c5c3001690
public class AverageIfs extends BaseIfs {
public BigDecimal averageIfs(List range, RangeCriteria>... rangeCriteria) {
var total = (new SumIfs()).sumIfs(range, rangeCriteria);
var elems = ifs(range, rangeCriteria);
return total.divide(BigDecimal.valueOf(elems.size()), MathContext.DECIMAL128);
}
}