简体   繁体   English

使用sumproduct的Excel 2013高级日期范围查找

[英]Excel 2013 advanced date range lookup using sumproduct

I am new to Stackoverflow, so please let me know me if there is not enough information. 我是Stackoverflow的新手,所以如果没有足够的信息,请告诉我。 I have had many helpfull insights by using StackOverflow in the past, but I cannot find any helpful thread online, so I hope you can help me. 过去,我通过使用StackOverflow获得了许多有用的见解,但是我找不到在线有用的线程,因此希望您能对我有所帮助。

I've been working on a excel (2013) problem for a while now. 我已经研究Excel(2013)问题已有一段时间了。 I am trying to build a marketing agenda to store and keep track of our mailing campaigns. 我正在尝试建立一个营销议程来存储和跟踪我们的邮件活动。 The campaigns themselves are send via another system, but we miss the ability to plan our mailing campaigns in advance. 这些活动本身是通过另一个系统发送的,但是我们错过了预先计划邮件活动的功能。 Since we are active on different markets in Europe, we decided to have a general mailing (for all regions) and a region specific mailing campaign (both are in the same agenda). 由于我们活跃于欧洲的不同市场,因此我们决定进行常规邮寄(针对所有区域)和针对特定区域的邮寄活动(两者都在同一议程中)。 Besides this we also want to display the mailing focus (different brands). 除此之外,我们还希望显示邮件的焦点(不同的品牌)。 It is my idea to return this as visual as possible (to make it usable for all users). 我的想法是尽可能返回视觉效果(使其对所有用户可用)。 I have add a small picture to show my desired end-result (however without any data at this moment). 我添加了一张小图以显示所需的最终结果(但是此刻没有任何数据)。

At this moment, the users are going to use a (Google)form to enter the campaign information and this data is downloaded to the worksheet (by doing so all users can add new campaigns and everyone always has access to the most recent data). 目前,用户将使用(Google)表单输入广告系列信息,并将此数据下载到工作表(通过这样做,所有用户都可以添加新的广告系列,并且每个人都始终可以访问最新数据)。 This part works well. 这部分效果很好。

I am using a helper sheet to check if the dates fall in a campaign range, if it does fall in a campaign range it should return the mailing ID (also the row number). 我正在使用帮助表检查日期是否在广告系列范围内,如果它确实在广告系列范围内,则应返回邮件ID(以及行号)。 I have another form which uses this data to search for the right brand and displays visually (with a lot of conditional formatting). 我还有另一种形式,可以使用这些数据来搜索正确的品牌并直观地显示(具有很多条件格式)。

The problem arises in the helper sheet (when I check if a date fall into a campaign range). 问题出现在帮助表中(当我检查日期是否在广告系列范围内时)。 I have been able to get it working (more or less) with the following formula: 我已经能够使用以下公式(或多或少)使其工作:

=IF(SUMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper!$D$2:$D$100>=$B4);RIJ(CountryHelper!$C$2:$C$100))=0;"";INDEX(CountryHelper!$A$2:$A$100;SOMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100))))

In this formula, CountryHelper!C:C is referencing the StartDate of the mailing campaing. 在此公式中,CountryHelper!C:C引用了邮件露营的StartDate。 D:D will reference the column of the EndDates and A:A has the mailing ID. D:D将引用EndDates的列,而A:A具有邮件ID。 Cell B4 is the date that needs to be checked. 单元格B4是需要检查的日期。

At first it looked this worked perfectly. 乍一看,这很完美。 If a date fell in a date range then it would return the ID. 如果日期落在日期范围内,则它将返回ID。 After a little playing around with this a problem came to light. 经过一番尝试之后,发现了一个问题。 It only works with non overlapping dates, once dates overlap excel will add the row numbers together and it would not work any more. 它仅适用于非重叠日期,一旦日期重叠,excel会将行号加在一起,将不再起作用。

Is it possible to get the sumproduct formula working and returning only the first ID. 是否有可能使sumproduct公式起作用并仅返回第一个ID。 I am aware that I then have to make another 2 formulas which return the second and third ID ( I am certain we do not get more than 3 overlapping dates). 我知道然后我必须制作另外两个公式来返回第二个和第三个ID(我确定我们得到的重叠日期不超过3个)。 This is also the part where I get lost. 这也是我迷路的部分。 I've tried to use a MIN and MAX variation wit the following sumproduct formula: 我尝试使用以下和乘积公式的MIN和MAX变量:

=SUMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper_RSEU!$D$1:$D$100>=$B4);ROW(CountryHelper!$C$1:$C$100))

This will return either a 0 (with MIN) or 100 (With MAX). 这将返回0(带有MIN)或100(带有MAX)。 I think this is caused by the formula (for now it only searches the first 99 rows). 我认为这是由公式引起的(目前,它仅搜索前99行)。 I also have ventured into VBA / UDF to get this done, but as I understand it this is not possible. 我也冒险使用VBA / UDF来完成此操作,但是据我所知这是不可能的。

Anyway, I am sorry for the long story, I hope that my problem is clear and you can help me. 无论如何,对于长话来说,我感到很抱歉,希望我的问题已经解决,您可以帮助我。 If you need any more information. 如果您需要更多信息。

Thank you! 谢谢!

empty Marketing Agenda overview 空的营销议程概述

The SUMPRODUCT is a kind of swiss army knife Excel function. SUMPRODUCT是一种瑞士军刀Excel功能。 But here it is wrong because, as you already have seen, it really calculates a SUM at the end. 但是这是错误的,因为,正如您已经看到的,它实际上是在最后计算一个SUM。 Mostly it works because it first multiplies the 0 or 1 of the conditions with the row numbers so only the row numbers which fulfills the conditions comes into the sum. 通常它之所以有效,是因为它首先将条件的0或1与行号相乘,因此只有满足条件的行号才成为总和。 But if two or more row numbers fulfil the conditions then they were added together. 但是,如果两个或多个行号满足条件,则将它们加在一起。

Are you familiar with array formulas? 您熟悉数组公式吗? The following array formula should be what you want: 以下数组公式应该是您想要的:

{=INDEX(CountryHelper!$A$2:$A$100;MIN(IF((CountryHelper!$C$2:$C$100<=$B4)*(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100)-1)))}

To create a array formula put the formula into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter]. 要创建数组公式,请将公式放入不带大括号的单元格中,然后按[Ctrl] + [Shift] + [Enter]。 Then the curly brackets should appear automaticaly. 然后大括号应自动出现。

How it works: 这个怎么运作:

{IF((CountryHelper!$C$2:$C$100<=$B4)*(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100)-1)}

Gets a array of row numbers or FALSE {FALSE, rowNumber, FALSE, ...}. 获取行号或FALSE {FALSE,rowNumber,FALSE,...}的数组。 If both conditions are fulfilled then it gets the row number - 1, if not then it gets FALSE. 如果两个条件都满足,则行号为1;否则,行为FALSE。 The MIN function then gets the smallest (row number - 1) from this array. 然后, MIN函数从该数组中获取最小的(行号-1)。 The INDEX then indicates this smallest (row number - 1) which fulfills the conditions. 然后, INDEX表示满足条件的最小值(行号-1)。

It subtracts 1 from the row number because your INDEX range starts at row 2. If the row number 2 fulfills the conditions then it is the index 1 within this range, if row number 3 fulfills the conditions, it is the index 2 and so on. 它从行号中减去1,因为您的INDEX范围从行2开始。如果行号2满足条件,则它是该范围内的索引1;如果行号3满足条件,则它是索引2,依此类推。

Why it only works as array formula? 为什么它只能用作数组公式? Because the IF function do not creates a array by default even if their "Value_if_true" is a range. 因为IF函数默认情况下不会创建数组,即使它们的“ Value_if_true”是一个范围。 Within the array context it does exact this. 在数组上下文中,它确实做到了这一点。

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

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