How can I compare a range of dates in two columns to find if a date exists in both or only one column?

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

How can I compare a range of dates in two columns to find if a date exists in both or only one column?

问题

IF E6 在范围 AK6:AK24 和范围 AL6:AL24 中存在,则返回 "Booth"
如果 E6 仅在范围 AK6:AK24 中存在,则返回 "Column 1"
如果 E6 仅在范围 AL6:AL24 中存在,则返回 "Column 2"

英文:

I have a range of dates, and i need to compare if the date exists in two columns:

How can I compare a range of dates in two columns to find if a date exists in both or only one column?

IF E6 exist in range AK6:AK24 and E6 exists in range AL6:AL24, returns "Booth"
IF E6 exists in range AK6:AK24 only, returns "Column 1"
IF E6 exists in range AL6:AL24 only, returns "Column 2"

答案1

得分: 1

请将这设置为您未提供有用数据的方式:

IF(AND(IFERROR(MATCH(A1,M3:M7,0),0),IFERROR(MATCH(A1,N3:N7,0),0)),"both",IF(IFERROR(MATCH(A1,M3:M7,0),0)>0,"col 1",IF(IFERROR(MATCH(A1,N3:N7,0),0)>0,"col 2")))

对于仅列1和两者的情况:
How can I compare a range of dates in two columns to find if a date exists in both or only one column?

How can I compare a range of dates in two columns to find if a date exists in both or only one column?

英文:

So, set this up as you did not supply useful data:

IF(AND(IFERROR(MATCH(A1,M3:M7,0),0),IFERROR(MATCH(A1,N3:N7,0),0)),"both",IF(IFERROR(MATCH(A1,M3:M7,0),0)>0,"col 1",IF(IFERROR(MATCH(A1,N3:N7,0),0)>0,"col 2")))

How can I compare a range of dates in two columns to find if a date exists in both or only one column?

For col 1 only and both:
How can I compare a range of dates in two columns to find if a date exists in both or only one column?

How can I compare a range of dates in two columns to find if a date exists in both or only one column?

答案2

得分: 1

以下是使用INDEX()XMATCH()以及BOOLEAN LOGIC辅助的另一种公式:

• 单元格E7中使用的公式:

=IFERROR(INDEX({"Column 1","Column 2","Both"}, XMATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2), {1,2,3})), "")

要解释公式的工作原理,请查看示例截图:

公式示例截图中的公式:

• 单元格AP7中:

=SUM(($AK$6:$AK$24=AO7)+(AO7=$AL$6:$AL$24)*2)

• 单元格AQ7中:

=XMATCH(AP7, {1,2,3})

• 单元格AR7中:

=IFERROR(INDEX({"Column 1","Column 2","Both"}, AQ7), "")

XMATCH()中的SUM()根据BOOLEAN LOGIC返回0123

=SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2)

XMATCH()返回相同的位置,但在没有匹配时有所帮助,因此返回#N/A

=XMATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2), {1,2,3})

最后,我们将其包装在IFERROR()中,以避免错误,并在INDEX()中获取所需的输出:

=IFERROR(INDEX({"Column 1","Column 2","Both"}, XMATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2), {1,2,3})), "")

另外,如果您的Excel版本没有XMATCH(),您也可以使用MATCH()函数:

=IFERROR(INDEX({"Column 1","Column 2","Both"}, MATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2), {1,2,3}, 0)), "")

**注意:**根据您的Excel版本,使用INDEX()MATCH()时需要按下CTRL+SHIFT+ENTER

但是,如果您使用的是MS365并且希望获得溢出效果,您可以使用一个单一公式BYCOL()

• 单元格E7中使用的公式:

=BYCOL(E6:AI6, LAMBDA(x, IFERROR(INDEX({"Column 1","Column 2","Both"}, XMATCH(SUM(($AK$6:$AK$24=x)+(x=$AL$6:$AL$24)*2), {1,2,3})), "")))

以下是另一种选择,使用CHOOSE()函数和BYCOL()

• 单元格E7中使用的公式(需要向右填充):

=IFERROR(CHOOSE(SUM((($AK$6:$AK$24=E$6)+($AL$6:$AL$24=E$6)*2)), "Column 1", "Column 2", "Both"), "")

或者,如果您想要一个溢出数组,可以使用以下公式:

=BYCOL(E6:AI6, LAMBDA(x, IFERROR(CHOOSE(SUM((($AK$6:$AK$24=x)+($AL$6:$AL$24=x)*2)), "Column 1", "Column 2", "Both"), "")))

以上是根据要求正常工作的公式的一些测试案例:

• 单元格AS7中:

=IFERROR(CHOOSE(SUM((($AK$6:$AK$24=AO7)+($AL$6:$AL$24=AO7)*2)), "Column 1", "Column 2", "Both"), "")
英文:

Here is an alternative formula using INDEX() & XMATCH() with the help of BOOLEAN LOGIC

How can I compare a range of dates in two columns to find if a date exists in both or only one column?


• Formula used in cell E7

=IFERROR(INDEX({"Column 1","Column 2","Both"},
XMATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2),{1,2,3})),"")

To Explain how the formula works look at the example screenshot:

How can I compare a range of dates in two columns to find if a date exists in both or only one column?


Formulas in the example screenshot :

• in cell AP7

=SUM(($AK$6:$AK$24=AO7)+(AO7=$AL$6:$AL$24)*2)

• in cell AQ7

=XMATCH(AP7,{1,2,3})

• in cell AR7

=IFERROR(INDEX({"Column 1","Column 2","Both"},AQ7),"")

• The SUM() within XMATCH() returns either 0 or 1 or 2 or 3 based on the BOOLEAN LOGIC

=SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2)

• The XMATCH() returns the same position but it helps when there is no match, and hence returns #N/A

=XMATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2),{1,2,3})

• Lastly we are wrapping it within IFERROR() to avoid errors and returns as blank while the INDEX() to get the desired output as needed.

=IFERROR(INDEX({"Column 1","Column 2","Both"},
XMATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2),{1,2,3})),"")

Alternatively, you can also use MATCH() function if you don't have XMATCH() in your version of Excel.

=IFERROR(INDEX({"Column 1","Column 2","Both"},
MATCH(SUM(($AK$6:$AK$24=E6)+(E6=$AL$6:$AL$24)*2),{1,2,3},0)),"")

Note: Based on your excel version need to press <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>ENTER</kbd> when using INDEX() with MATCH()


However, if you are in MS365 and want a spill effect then you can do it, with one single formula using BYCOL()

• Formula used in cell E7

=BYCOL(E6:AI6,LAMBDA(x,
IFERROR(INDEX({&quot;Column 1&quot;,&quot;Column 2&quot;,&quot;Both&quot;},
XMATCH(SUM(($AK$6:$AK$24=x)+(x=$AL$6:$AL$24)*2),{1,2,3})),&quot;&quot;)))

How can I compare a range of dates in two columns to find if a date exists in both or only one column?


Here is one more alternative, using the CHOOSE() Function with BYCOL()

How can I compare a range of dates in two columns to find if a date exists in both or only one column?


• Formula used in cell E7 --> Needs to fill right!

=IFERROR(CHOOSE(SUM((($AK$6:$AK$24=E$6)+($AL$6:$AL$24=E$6)*2)),&quot;Column 1&quot;,&quot;Column 2&quot;,&quot;Both&quot;),&quot;&quot;)

Or, if you want a spill array then

=BYCOL(E6:AI6,LAMBDA(x,
IFERROR(CHOOSE(SUM((($AK$6:$AK$24=x)+($AL$6:$AL$24=x)*2)),
&quot;Column 1&quot;,&quot;Column 2&quot;,&quot;Both&quot;),&quot;&quot;)))

Few Test Cases for the above formula is working as per the requirements:

How can I compare a range of dates in two columns to find if a date exists in both or only one column?


• in cell AS7

=IFERROR(CHOOSE(SUM((($AK$6:$AK$24=AO7)+($AL$6:$AL$24=AO7)*2)),&quot;Column 1&quot;,&quot;Column 2&quot;,&quot;Both&quot;),&quot;&quot;)

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

发表评论

匿名网友

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

确定