基于多个月的月份的Sumif金额

时间:2016-02-20 07:10:48

标签: excel sumifs

我有以下格式的Excel数据

Date         Amount
01-Jan-16     23.94
12-Jan-16     17.96
26-Jan-16     32.92
03-Feb-16     38.90
20-Feb-16     62.27
26-Feb-16     45.89

我想将特定月份的金额字段相加,即我想在1月和2月分别总结金额。

这是我迄今为止尝试的代码,我在之前提出的问题中找到了该代码(参见Excel Formula to SUMIF date falls in particular month)。

=SUM(IF(MONTH(A:A)=1,B:B,0))

它适用于1月,但当我将1改为2时,它返回零。

=SUM(IF(MONTH(A:A)=2,B:B,0))

sumifs会更好吗?

2 个答案:

答案 0 :(得分:3)

以下是另外两种方法: -

   table.products {
    table-layout: fixed;
    }    

    table.products input.add[type="button"]{

    color:white;
    width: 100%;
    background-color: #27af60;
    border: none;
    letter-spacing: .8px;

    }

    table.products input.del[type="button"]{

    color:white;
    width: 100%;
    background-color: #c0392b;
    border: none;
    letter-spacing: .8px;
    }

    table.products input.submit[type="submit"]{

    color:white;
    width: 100%;
    background-color: gray;
    border: none;
    letter-spacing: .8px;
    }

<table class="products">  
    <tr>
        <td colspan="2"><input class="add" type="button" value="Add a Product"></td>
        <td colspan="2"><input class="del" type="button" value="Delete a Product"></td>
    </tr>
    <tr>
        <td colspan="4"><input class="submit" name="prod_submit" type="submit" value="Submit Products"></td>
    </tr>

</table>

根据需要进行更改以获得其他月份的总计。

我已将结果放在此屏幕截图中的原始数组公式旁边: -

enter image description here

答案 1 :(得分:2)

使用特定范围而不是完整列。您必须将公式用作数组公式。

=SUM(IF(MONTH($A$2:$A$1000)=1,$B$2:$B$1000,0))

CTRL + SHIFT + ENTER 将公式计算为数组公式。