简体   繁体   English

Excel为日期范围返回多个值,并对单个日期项求和

[英]Excel returning multiple values for a date range, with a single date items summed

I have the opposite query for this question: 我对这个问题有相反的查询:

Excel - Lookup to return multiple values in between date range Excel - 查找以在日期范围之间返回多个值

The solution is given for the above query in the following link also: 以下链接也为上述查询提供了解决方案:

https://www.get-digital-help.com/2009/12/13/formula-for-matching-a-date-within-a-date-range-in-excel/ https://www.get-digital-help.com/2009/12/13/formula-for-matching-a-date-within-a-date-range-in-excel/

But my query is that for multiple date ranges, how do I find the total bookings of a single date. 但我的疑问是,对于多个日期范围,如何查找单个日期的总预订量。

I wish to build a calendar which will allow me to work out how many booking I have for a certain day. 我希望建立一个日程表,这样我就可以计算出某一天的预订量。 All the bookings are for 1 or more items and I want the total items which will be there on a single day, across a date calendar range. 所有预订都是针对一件或多件物品而且我想要在一天中在日期日历范围内的总物品。

日期范围和该日期范围内的总项目,包含日历

On the calendar on the right side, I wish to add the total items which will be staying over during that specified date. 在右侧的日历上,我希望添加在指定日期期间将停留的总项目。

So, in the example, on the 26th December, a total of 6 items will be there. 因此,在该示例中,在12月26日,总共有6个项目。 And for 5th December there is only 1, while for 1st December there are no items. 12月5日只有1,而12月1日没有项目。

Would like to have these numbers in the calendar on the right. 想在右边的日历中有这些数字。

I have tried using VLOOKUP, LOOKUP, INDEX and MATCH. 我尝试过使用VLOOKUP,LOOKUP,INDEX和MATCH。 Also, tried the SUMPRODUCT mentioned, but those seem to give a single range and number for that range, but not the multiple values across a date range. 此外,尝试过所提到的SUMPRODUCT,但这些似乎给出了该范围的单个范围和数字,但不是日期范围内的多个值。

https://chandoo.org/wp/range-lookup-excel/ https://chandoo.org/wp/range-lookup-excel/

Formulae I tried are, for the 26th December date are: 我试过的公式是,12月26日的日期是:

=(LOOKUP(H10,((Table1[Date From]):(Table1[Date To])),Table1[Items from]))

=SUMIF(Table1[Item],(LOOKUP(2,1/(Table1[Date From]<=H10)/(Table1[Date To]>=H10))))

=INDEX(Table1[Item from],MATCH(H10,LOOKUP(H10,Table1[[Date From]:[Date To]])))

For Dec 26th ( and keeping your original structure ) 12月26日( 保持原有结构

=SUMIFS(Bookings[[Items]:[Items]],Bookings[[Date From]:[Date From]],"<=" &H10,Bookings[[Date To]:[Date To]],">="&H10)

Note that I used the absolute address structured reference form so you can at least fill/drag across a row, without changing the columns from the table. 请注意,我使用了绝对地址结构化引用表单,因此您至少可以在一行中填充/拖动,而无需更改表中的列。

If you want to make things even easier, you can replace the H10 reference with a computed reference, but at the cost of using OFFSET which is a volatile function. 如果你想让事情更容易,你可以用计算引用替换H10引用,但代价是使用OFFSET这是一个易失性函数。

=SUMIFS(Bookings[[Items]:[Items]],Bookings[[Date From]:[Date From]],"<=" &OFFSET(H$1,ROW()-2,0),Bookings[[Date To]:[Date To]],">="&OFFSET(H$1,ROW()-2,0))

You might also be able to construct a computed cell reference using the INDEX function, which would be non-volatile. 您也可以使用INDEX函数构造计算单元格引用,该函数是非易失性的。

Updated answer with array formulas 更新了数组公式的答案

Sorry for not understanding your first request. 很抱歉不理解您的第一个请求。

You can use the following array formula in a "single cell" 您可以在“单个单元格”中使用以下数组公式

{= SUM( IF( (E2 >=$B$2:$B$8 ) * (E2<=$C$2:$C$8) ; $A$2:$A$8 ; 0 ))} 

Where column e contains the target dates, columns a , b and c contain items , from and to . 如果列e包含目标日期,则列abc包含itemsfromto

This formula is expansible and copiable to other cells where e2 will be relatively changed for each target date. 该公式是可扩展的,并且可以与其他单元格协作,其中e2将针对每个目标日期进行相对更改。 This is easily adaptable to your month table. 这很容易适应您的月份表。 Put the formula below the first date, then expand horizontally and copy/paste to the other rows. 将公式放在第一个日期下面,然后水平展开并复制/粘贴到其他行。

See picture: 见图:

列日期的新图片

Old answer 老答案

  • Create a separate cell with your target date. 使用目标日期创建单独的单元格。 Suppose $e$1 . 假设$e$1
  • Create on e2 this formula: =if( and( $e$1 >= c2 ; $e$1 <= d2 ); a2; 0) e2创建这个公式: =if( and( $e$1 >= c2 ; $e$1 <= d2 ); a2; 0)
  • Expand it and sum at the bottom. 展开它并在底部求和。

Sorry for my formulas in Portuguese in the image (se = if ; e = and): 对不起我的图像中的葡萄牙语公式(se = if; e =和):

图片

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

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