Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation/Statistical :: Add MAXIFS, MINIFS, COUNTIFS and Remove MINIF, MAXIF #1059

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
#1056 - replace invalid minif/maxif functions by not implemented mini…
…fs/maxifs

minif/maxif is not support in Excel, Google Spreadsheets, Libreoffice
https://support.office.com/en-us/article/excel-functions-alphabetical-b3944572-255d-4efb-bb96-c6d90033e188#bm13
zdenekdrahos committed Jul 5, 2019
commit c275a77e565d6babf490900d2f074e4b17802379
4 changes: 2 additions & 2 deletions docs/references/function-list-by-category.md
Original file line number Diff line number Diff line change
@@ -361,12 +361,12 @@ LOGINV | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::LOGINV
LOGNORMDIST | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::LOGNORMDIST
MAX | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MAX
MAXA | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MAXA
MAXIF | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MAXIF
MAXIFS | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MAXIFS
MEDIAN | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MEDIAN
MEDIANIF | **Not yet Implemented**
MIN | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MIN
MINA | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MINA
MINIF | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MINIF
MINIFS | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MINIFS
MODE | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MODE
MODE.SNGL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MODE
NEGBINOMDIST | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::NEGBINOMDIST
4 changes: 2 additions & 2 deletions docs/references/function-list-by-name.md
Original file line number Diff line number Diff line change
@@ -295,7 +295,7 @@ Excel Function | Category | PhpSpreadsheet Function
MATCH | CATEGORY_LOOKUP_AND_REFERENCE | \PhpOffice\PhpSpreadsheet\Calculation\LookupRef::MATCH
MAX | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MAX
MAXA | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MAXA
MAXIF | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MAXIF
MAXIFS | CATEGORY_STATISTICAL | **Not yet Implemented**
MDETERM | CATEGORY_MATH_AND_TRIG | \PhpOffice\PhpSpreadsheet\Calculation\MathTrig::MDETERM
MDURATION | CATEGORY_FINANCIAL | **Not yet Implemented**
MEDIAN | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MEDIAN
@@ -304,7 +304,7 @@ MID | CATEGORY_TEXT_AND_DATA | \PhpOffice\PhpSpreadsheet
MIDB | CATEGORY_TEXT_AND_DATA | \PhpOffice\PhpSpreadsheet\Calculation\TextData::MID
MIN | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MIN
MINA | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MINA
MINIF | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::MINIF
MINIFS | CATEGORY_STATISTICAL | **Not yet Implemented**
MINUTE | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::MINUTE
MINVERSE | CATEGORY_MATH_AND_TRIG | \PhpOffice\PhpSpreadsheet\Calculation\MathTrig::MINVERSE
MIRR | CATEGORY_FINANCIAL | \PhpOffice\PhpSpreadsheet\Calculation\Financial::MIRR
12 changes: 6 additions & 6 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
@@ -1356,10 +1356,10 @@ class Calculation
'functionCall' => [Statistical::class, 'MAXA'],
'argumentCount' => '1+',
],
'MAXIF' => [
'MAXIFS' => [
'category' => Category::CATEGORY_STATISTICAL,
'functionCall' => [Statistical::class, 'MAXIF'],
'argumentCount' => '2+',
'functionCall' => [Statistical::class, 'MAXIFS'],
'argumentCount' => '3+',
],
'MDETERM' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
@@ -1401,10 +1401,10 @@ class Calculation
'functionCall' => [Statistical::class, 'MINA'],
'argumentCount' => '1+',
],
'MINIF' => [
'MINIFS' => [
'category' => Category::CATEGORY_STATISTICAL,
'functionCall' => [Statistical::class, 'MINIF'],
'argumentCount' => '2+',
'functionCall' => [Statistical::class, 'MINIFS'],
'argumentCount' => '3+',
],
'MINUTE' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
70 changes: 12 additions & 58 deletions src/PhpSpreadsheet/Calculation/Statistical.php
Original file line number Diff line number Diff line change
@@ -2105,45 +2105,22 @@ public static function MAXA(...$args)
}

/**
* MAXIF.
* MAXIFS.
*
* Counts the maximum value within a range of cells that contain numbers within the list of arguments
*
* Excel Function:
* MAXIF(value1[,value2[, ...]],condition)
* MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
*
* @category Mathematical and Trigonometric Functions
* @category Statistical Functions
*
* @param mixed $aArgs Data values
* @param string $condition the criteria that defines which cells will be checked
* @param mixed $sumArgs
* @param mixed $args Data range and criterias
*
* @return float
*/
public static function MAXIF($aArgs, $condition, $sumArgs = [])
public static function MAXIFS(...$args)
{
$returnValue = null;

$aArgs = Functions::flattenArray($aArgs);
$sumArgs = Functions::flattenArray($sumArgs);
if (empty($sumArgs)) {
$sumArgs = $aArgs;
}
$condition = Functions::ifCondition($condition);
// Loop through arguments
foreach ($aArgs as $key => $arg) {
if (!is_numeric($arg)) {
$arg = Calculation::wrapResult(strtoupper($arg));
}
$testCondition = '=' . $arg . $condition;
if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
if (($returnValue === null) || ($arg > $returnValue)) {
$returnValue = $arg;
}
}
}

return $returnValue;
return Functions::DUMMY();
}

/**
@@ -2268,45 +2245,22 @@ public static function MINA(...$args)
}

/**
* MINIF.
* MINIFS.
*
* Returns the minimum value within a range of cells that contain numbers within the list of arguments
*
* Excel Function:
* MINIF(value1[,value2[, ...]],condition)
* MINIFS(min_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
*
* @category Mathematical and Trigonometric Functions
* @category Statistical Functions
*
* @param mixed $aArgs Data values
* @param string $condition the criteria that defines which cells will be checked
* @param mixed $sumArgs
* @param mixed $args Data range and criterias
*
* @return float
*/
public static function MINIF($aArgs, $condition, $sumArgs = [])
public static function MINIFS(...$args)
{
$returnValue = null;

$aArgs = Functions::flattenArray($aArgs);
$sumArgs = Functions::flattenArray($sumArgs);
if (empty($sumArgs)) {
$sumArgs = $aArgs;
}
$condition = Functions::ifCondition($condition);
// Loop through arguments
foreach ($aArgs as $key => $arg) {
if (!is_numeric($arg)) {
$arg = Calculation::wrapResult(strtoupper($arg));
}
$testCondition = '=' . $arg . $condition;
if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
if (($returnValue === null) || ($arg < $returnValue)) {
$returnValue = $arg;
}
}
}

return $returnValue;
return Functions::DUMMY();
}

//
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Calculation/functionlist.txt
Original file line number Diff line number Diff line change
@@ -224,13 +224,15 @@ LOWER
MATCH
MAX
MAXA
MAXIFS
MDETERM
MDURATION
MEDIAN
MID
MIDB
MIN
MINA
MINIFS
MINUTE
MINVERSE
MIRR
43 changes: 43 additions & 0 deletions tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Calculation;

use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;

class StatisticalTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}

/**
* @dataProvider providerMAXIFS
*/
public function testMAXIFS($expectedResult, ...$args)
{
$result = Statistical::MAXIFS(...$args);
self::assertEquals('#Not Yet Implemented', $result);
}

public function providerMAXIFS()
{
return require 'data/Calculation/Statistical/MAXIFS.php';
}

/**
* @dataProvider providerMINIFS
*/
public function testMINIFS($expectedResult, ...$args)
{
$result = Statistical::MINIFS(...$args);
self::assertEquals('#Not Yet Implemented', $result);
}

public function providerMINIFS()
{
return require 'data/Calculation/Statistical/MINIFS.php';
}
}
44 changes: 44 additions & 0 deletions tests/data/Calculation/Statistical/MAXIFS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

return [
[
2,
[
[1],
[2],
[3],
],
[
['Y'],
['Y'],
['N'],
],
'=Y',
[
['H'],
['H'],
['H'],
],
'=H',
],
[
2,
[
[1],
[2],
[3],
],
[
['A'],
['B'],
['C'],
],
'=B',
[
['C'],
['B'],
['A'],
],
'=B',
],
];
44 changes: 44 additions & 0 deletions tests/data/Calculation/Statistical/MINIFS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

return [
[
1,
[
[1],
[2],
[3],
],
[
['Y'],
['Y'],
['N'],
],
'=Y',
[
['H'],
['H'],
['H'],
],
'=H',
],
[
2,
[
[1],
[2],
[3],
],
[
['A'],
['B'],
['C'],
],
'=B',
[
['C'],
['B'],
['A'],
],
'=B',
],
];