mysql max(if)

Excel doesn’t have a MAXIF function, but we’re able to create our own version, by combining the MAX and IF functions. But how about a bigger dream - MAX IF with multiple criteria? Could we create our own MAXIFS function too, with multiple IFs?

Excel没有MAXIF函数,但是我们可以结合使用MAX和IF函数来创建自己的版本。 但是,实现更大的梦想-具有多个条件的MAX IF怎么样? 我们是否也可以使用多个IF创建自己的MAXIFS函数?

使用MAX和IF (Using MAX and IF)

Last week, we used MAX and IF in an array-entered formula, to find the latest date that a product price was changed. Remember to press Ctrl + Shift + Enter after typing this formula, instead of just pressing Enter.

上周,我们在数组输入的公式中使用了MAX和IF来查找产品价格更改的最新日期。 记住在键入此公式后按Ctrl + Shift + Enter ,而不是仅按Enter。

=MAX(IF($A$2:$A$9=A12,$B$2:$B$9))

= MAX(IF($ A $ 2:$ A $ 9 = A12,$ B $ 2:$ B $ 9))

Note: For more information on array formulas, I recommend Mike Girvin’s book, Ctrl+Shift+Enter: Mastering Excel Array Formulas.

注意:有关数组公式的更多信息,我建议Mike Girvin的书Ctrl + Shift + Enter:精通Excel数组公式。

客户和产品 (Customers and Products)

This week, our sample data has another column included – the customer name.

本周,我们的样本数据包括另一列–客户名称。

We’d like to revise that MAX and IF formula, to check for the latest date that a product price was changed, for a specific customer.

我们想要修改MAX和IF公式,以检查特定客户的产品价格更改的最新日期。

选择客户和产品 (Select a Customer and Product)

The product name, Paper, is entered in cell A12, and the customer name, ABC,  is in B2. By manually checking the list, we can see that the latest price change was on June 1st.

产品名称Paper在单元格A12中输入,客户名称ABC在B2中。 通过手动检查清单,我们可以看到最新的价格变化是在6月1日。

修改MAX和IF公式 (Modify the MAX and IF formula)

The original formula just checked the product name, and then returned the latest date, from column B.

原始公式只是检查了产品名称,然后从B列返回了最新日期。

=MAX(IF($A$2:$A$9=A12,$B$2:$B$9))

= MAX(IF($ A $ 2:$ A $ 9 = A12,$ B $ 2:$ B $ 9))

Now, we want the formula to check both the product name (column A), and the customer name (column B), and return the latest date (column C).

现在,我们希望公式同时检查产品名称(A列)和客户名称(B列),并返回最新日期(C列)。

Entered in cell C12, the formula will start the same, by checking the product name:

在单元格C12中输入,通过检查产品名称,公式将以相同的开头:

=MAX(IF($A$2:$A$9=A12,

= MAX( IF($ A $ 2:$ A $ 9 = A12,

Then we’ll add a second IF function, to check the customer name:

然后,我们将添加第二个IF函数,以检查客户名称:

=MAX(IF($A$2:$A$9=A12,IF($B$2:$B$9=B12,

= MAX( IF($ A $ 2:$ A $ 9 = A12, IF($ B $ 2:$ B $ 9 = B12,

Finally, we’ll get the date from column C:

最后,我们将从C列获取日期:

=MAX(IF($A$2:$A$9=A12, IF($B$2:$B$9=B12,$C$2:$C$9)))

= MAX(IF($ A $ 2:$ A $ 9 = A12,IF($ B $ 2:$ B $ 9 = B12,$ C $ 2:$ C $ 9)))

IMPORTANT: After typing the formula, array-enter it, by pressing Ctrl + Shift + Enter.

重要说明 :键入公式后,按Ctrl + Shift + Enter进行数组输入

The formula is copied down to cell C13, and both cells show the correct result – June 1st.

公式被复制到单元格C13,并且两个单元格都显示正确的结果– 6月1日。

获取最新价格 (Get the Latest Price)

Finally, the Latest price is calculated using SUMIFS (Excel 2007 or later):

最后,使用SUMIFS(Excel 2007或更高版本)计算最新价格:

=SUMIFS($D$2:$D$9,$A$2:$A$9,A12,$C$2:$C$9,C12)

= SUMIFS($ D $ 2:$ D $ 9,$ A $ 2:$ A $ 9,A12,$ C $ 2:$ C $ 9,C12)

or SUMPRODUCT:

或SUMPRODUCT:

=SUMPRODUCT(($A$2:$A$9=A13)*($C$2:$C$9=C13)*($D$2:$D$9))

= SUMPRODUCT(($ A $ 2:$ A $ 9 = A13)*($ C $ 2:$ C $ 9 = C13)*($ D $ 2:$ D $ 9))

下载样本文件 (Download the Sample File)

You can download the sample file from the MIN and MAX Functions page on my website.

您可以从我的网站的MIN和MAX Functions页面下载示例文件。

翻译自: https://contexturesblog/archives/2013/11/19/using-max-if-with-multiple-criteria/

mysql max(if)

更多推荐

mysql max(if)_将MAX IF与多个条件一起使用