简体   繁体   English

日期范围为文本的日期范围内的数据总和

[英]Sum array of data within date range where date is text

I have an Excel table of the following format: 我有以下格式的Excel表:

在此处输入图片说明

And I would like to answer the following question using Excel formulae: 我想使用Excel公式回答以下问题:

  • What is the sum for Disney during 17-Nov until 20-Nov? 迪士尼在11月11日至11月20日期间的总和是多少?

My attempts I tried the following approaches, unsuccessfully: 我的尝试尝试了以下方法,但均未成功:

  1. Using SUMIFS with an array: SUMIFS与数组配合使用:

    =SUMIFS(c4:g8,c3:g3,i1,b4:b8,">="&i2,b4:b8,"<="&i3)

where i1 contains Disney , i2 contains 17-Nov in the date format, and i3 contains 20-Nov in the date format. 其中i1包含Disney ,i2包含日期格式17-Nov日,而i3包含日期格式20-Nov日。

But this doesn't work because we are submitting an array where we must specify a range of cells. 但这是行不通的,因为我们要提交一个数组,其中必须指定一个单元格范围。 So I tried the following method: 所以我尝试了以下方法:

  1. Using SUMIFS with a range: 在一定范围内使用SUMIFS

    =SUMIFS(c4:g8,b4:b8,">="&i2,b4:b8,"<="&i3)

But this doesn't work either, since I think we are using the > , < operators for text (the date values in the table). 但这也不起作用,因为我认为我们对文本(表中的日期值)使用了><运算符。

So, what to do? 那么该怎么办?
Should I change the format of the table completely? 我应该完全改变表格的格式吗?
Should I convert it back to range? 我应该将其转换回范围吗?

You can use Index and Match to select the column to sum. 您可以使用“ IndexMatch来选择要累加的列。

Something like this 像这样

=SUMIFS(INDEX($B$4:$G$8,,MATCH(I1,$B$3:$G$3)),$B$4:$B$8,">="&I2,$B$4:$B$8,"<="&I3)

You can also take advantage of the Table Structured Addressing like this 您还可以像这样利用表结构化寻址
(tested in Excel 2010, so Table formats may be slighly different in Excel 2007) (在Excel 2010中进行了测试,因此表格格式在Excel 2007中可能略有不同)

=SUMIFS(INDEX(MyTable,,MATCH(I1,MyTable[#Headers])),MyTable[Date],">="&I2,MyTable[Date],"<="&I3)

This is what Sumproduct() is good for. 这就是Sumproduct()的优点。

=SUMPRODUCT($C$4:$G$8*($C$3:$G$3=company)*($B$4:$B$8>=startDate)*($B$4:$B$8<=finishDate))

在此处输入图片说明

company , startDate and finishDate are named cells for A11, B11 and C11. companystartDatefinishDate分别命名为A11,B11和C11的单元格。 Dates in the table and in row 11 are real dates. 表中和第11行中的日期是真实日期。

If you store the date as text values, you won't be able to calculate data in a date range. 如果将日期存储为文本值,则将无法计算日期范围内的数据。 The dates need to be real dates. 日期必须是真实日期。 Text cannot be used to define date ranges. 文本不能用于定义日期范围。

为了获得更大的灵活性,我将考虑“平整”数据( 例如 ),然后使用数据透视表过滤工具。

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

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