使用比较日期范围的多个条件求和值

时间:2017-05-06 06:38:09

标签: excel excel-formula sumifs

我的数据:

A          B        C
1/1/2010   1200.00  1/1/2010
1/10/2010  300.00   1/10/2010
2/1/2010   -500.00  2/2/2010
2/5/2010   900.00   2/6/2010
3/1/2010   670.00   3/1/2010

我需要公式:

  1. B IF A和C的值之和等于并且属于 2010年1月,
  2. B IF A和C的值之和不等于且属于2010年2月
  3. 鉴于两个日期(A和C)都在同一个月;他们只是相隔几天。我已经使用了sumproduct,因为A和C是相同的,但我很困惑在哪里放置日期范围的标准。

2 个答案:

答案 0 :(得分:1)

您需要使用以下公式。 请注意,这些是数组公式,您必须使用 Ctrl + Shift + Enter 确认它们,而不是仅按 Enter - 键。

你的第一个公式:

In [91]: df.AgeGroups = \
             df.AgeGroups.replace([r'^(\d{1})\_', r'_(\d{1})$'], 
                                  [r'0\1_',r'_0\1'],
                                  regex=True)

你的第二个公式:

In [93]: df
Out[93]:
   AgeGroups     Factor Cancer  Frequency
0      00_05  wo-statin    Yes          0
1      06_10  wo-statin    Yes          0
2      11_15  wo-statin    Yes          1
3      16_20  wo-statin    Yes          1
4      21_25  wo-statin    Yes         23
5      26_30  wo-statin    Yes         50
6      31_35  wo-statin    Yes         70
7      36_40  wo-statin    Yes        107
8      41_45  wo-statin    Yes        168
9      46_50  wo-statin    Yes        412
..       ...        ...    ...        ...
70     51_55   w-statin    Yes         17
71     56_60   w-statin    Yes         24
72     61_65   w-statin    Yes         50
73     66_70   w-statin    Yes        113
74     71_75   w-statin    Yes        198
75     76_80   w-statin    Yes        105
76     81_85   w-statin    Yes         37
77     86_90   w-statin    Yes         18
78     91_95   w-statin    Yes          2
79    96_100   w-statin    Yes          0

[40 rows x 4 columns]

答案 1 :(得分:1)

总和列B,其中列A等于列C,两列都在2010年1月的月份和年份,

=SUMPRODUCT((TEXT(A1:A5, "mmyyyy")="012010")*(A1:A5=C1:C5), B1:B5)

总和列B,其中A列不等于C列,两列都在2010年2月的月份和年份,

=SUMPRODUCT((TEXT(A1:A5, "mmyyyy")="022010")*(TEXT(C1:C5, "mmyyyy")="022010")*(A1:A5<>C1:C5), B1:B5)

http://processors.wiki.ti.com/index.php/OMAP_Wireless_Connectivity_NLCP_WiFi_Direct_Configuration_Scripts#Connect_in_pbc_.28Push_button_Control.29

相关问题