计算日期范围在另一个日期范围内的行数。

huangapple go评论52阅读模式
英文:

Count the number of rows where date range is within another date range

问题

Range A From To
2023年1月1日 2023年3月31日
Test Ranges From To
A 2023年2月1日 2023年2月15日
B 2023年3月15日 2023年6月30日
C 2022年12月15日 2023年1月15日
D 2023年6月1日 2023年6月30日

创建一个公式来计算测试范围的行数,并将它们包括在内,如果它们的范围至少部分包含在范围A内:

范围A、B和C都在范围A内,所以答案是:

3

链接: https://docs.google.com/spreadsheets/d/1TM7CrZfAevGBGUrxaWzpab7ybl6SsNdCI2c0G61VhJE/edit#gid=0

编辑:答案应该能够处理可变数量的测试范围 - 类似于"D2:D",如果下面的行为空,它们将被忽略。

英文:

I recently asked a different question that was similar but I'm not able to map that answer to my actual need.

Range A From To
1 Jan 2023 31 Mar 2023
Test Ranges From To
A 1 Feb 2023 15 Feb 2023
B 15 Mar 2023 30 Jun 2023
C 15 Dec 2022 15 Jan 2023
D 1 Jun 2023 30 Jun 2023

Create a formula that counts the Test Range ROWS and include them if their range is at least partially part of RANGE A:

Ranges A, B and C are within Range A so the answer is:

3

https://docs.google.com/spreadsheets/d/1TM7CrZfAevGBGUrxaWzpab7ybl6SsNdCI2c0G61VhJE/edit#gid=0

EDIT: The answer should be able to handle a variable number of TEST RANGES - something like "D2:D", and if the rows below are empty they would be ignored.

答案1

得分: 1

=SUM(MAP(B7:B15,C7:C15,LAMBDA(bbb,ccc,IF(bbb="",IF(AND(OR(B3<=bbb,B3<=ccc),OR(ccc<=$C$3,bbb<=$C$3))=TRUE,TRUE,FALSE)*1))))

=SUM(INDEX(IF(B7:B15="",IF((B7:B15>=$B$3)(B7:B15<=$C$3)+(C7:C15>=$B$3)(C7:C15<=$C$3)>0,TRUE,FALSE)*1)))

英文:

You can use either of the following f

=SUM(MAP(B7:B15,C7:C15,
LAMBDA(bbb,ccc,IF(bbb=&quot;&quot;,&quot;&quot;,
      IF(AND(OR(B3&lt;=bbb,B3&lt;=ccc),OR(ccc&lt;=$C$3,bbb&lt;=$C$3))=TRUE,TRUE,FALSE))*1)))

OR

=SUM(INDEX(IF(B7:B15=&quot;&quot;,&quot;&quot;, 
       IF((B7:B15&gt;=$B$3)*(B7:B15&lt;=$C$3)+(C7:C15&gt;=$B$3)*(C7:C15&lt;=$C$3)&gt;0,TRUE,FALSE)*1)))

(Do adjust the formulae according to your ranges and locale)

计算日期范围在另一个日期范围内的行数。

答案2

得分: 0

以下是您要翻译的内容:

尝试以下公式 -

=SUM(MAP(INDEX((B7:B10>=B3)(B7:B10<=C3)),INDEX((C7:C10>=B3)(C7:C10<=C3)),LAMBDA(x,y,--OR(x,y))))

简化公式 -

=SUM(INDEX(--(((B7:B10>=B3)(B7:B10<=C3)+(C7:C10>=B3)(C7:C10<=C3))>0)))

英文:

Try the following formula-

=SUM(MAP(INDEX((B7:B10&gt;=B3)*(B7:B10&lt;=C3)),INDEX((C7:C10&gt;=B3)*(C7:C10&lt;=C3)),LAMBDA(x,y,--OR(x,y))))

Simplified formula-

=SUM(INDEX(--(((B7:B10&gt;=B3)*(B7:B10&lt;=C3)+(C7:C10&gt;=B3)*(C7:C10&lt;=C3))&gt;0)))

计算日期范围在另一个日期范围内的行数。

huangapple
  • 本文由 发表于 2023年5月17日 09:46:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268080.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定