英文:
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:
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")))
英文:
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")))
答案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
返回0
、1
、2
或3
:
=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
• 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:
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({"Column 1","Column 2","Both"},
XMATCH(SUM(($AK$6:$AK$24=x)+(x=$AL$6:$AL$24)*2),{1,2,3})),"")))
Here is one more alternative, using the CHOOSE()
Function with BYCOL()
• 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)),"Column 1","Column 2","Both"),"")
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)),
"Column 1","Column 2","Both"),"")))
Few Test Cases for the above formula is working as per the requirements:
• in cell AS7
=IFERROR(CHOOSE(SUM((($AK$6:$AK$24=AO7)+($AL$6:$AL$24=AO7)*2)),"Column 1","Column 2","Both"),"")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论