简体   繁体   English

具有DATE标准的SUMIFS(仅匹配年份和月份)

[英]SUMIFS with DATE criteria (match only year and month)

The data I am working with is daily, whereas the data I am importing values from is monthly. 我正在使用的数据是每天,而我从中导入值的数据是每月。

I used SUMIFS and wanted to set criteria as YEAR & MONTH only. 我使用SUMIFS,并希望将条件设置为“仅年份和月份”。 So that in the daily table, it returns the same value for 30/31 days of the corresponding month. 因此,在每日表格中,它会在对应月份的30/31天中返回相同的值。 It only returns 0's so far. 到目前为止,它仅返回0。

=SUMIFS('EA-04'!$D:$D,'EA-04'!$A:$A,DATE(YEAR($A2),MONTH($A2),1))/(DATE(YEAR($A2),MONTH($A2)+1,1)-DATE(YEAR($A2),MONTH($A2),1))

The problem you have is that you can't change the format of each individual cell in the range that you want to interrogate but you can test if each date in that range falls within a certain date range ( greater than or less than) So, if the value in cell A2 is the first of the month 1st October 2018 for example then you can use 您遇到的问题是,您无法在您要询问的范围内更改每个单元格的格式,但是可以测试该范围内的每个日期是否在某个日期范围内(大于或小于),因此,例如,如果单元格A2中的值是2018年10月1日当月的第一天,则可以使用

=SUMIFS('EA-04'!$D:$D,'EA-04'!$A:$A,”>=”&$A2, 'EA-04'!$A:$A,”<”&EDATE($A2,1))

The formula says less than or equal to 1st October 2018 or less that 1st of November 2018 公式显示小于或等于2018年10月1日或小于2018年11月1日

The EDATE(date,1) function adds 1 calendar month to the date in A2 so the 1st of the month becomes the first of the next month regardless of the number of days in the source month. EDATE(date,1)函数向A2中的日期添加1个日历月,因此无论源月中的天数如何,该月的1号都会成为下个月的第一号。

If the value in cell A2 is not the 1st then you can use this formula to change it to the 1st 如果单元格A2中的值不是第一,则可以使用此公式将其更改为第一

=SUMIFS('EA-04'!$D:$D,'EA-04'!$A:$A,”>=”&$A2-(day($A2))+1, 'EA-04'!$A:$A,”<”&EDATE($A2-(day($A2))+1,1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM