尝试找到符合复杂条件的匹配项。

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

Trying to find matches to complex criteria

问题

我的大脑试图弄清楚这个问题时感到疼痛,但我知道有一种方法。

我正在尝试编写一个公式,执行以下操作:对于每个“Schedule”标签单元格(即每个学生和课程时间段),搜索与学生列相对应的“Survey”标签列,找到第一个排名为6且匹配课程时间段的课程,并返回排名和课程名称(来自“Survey”标签列B),如果找不到任何匹配项,则搜索第一个排名为5的课程,然后是排名为4的,然后是排名为3的,如果仍找不到,则返回“NO MATCH”。

一个复杂因素是课程可以是学期长度全年(两个学期),因此学期匹配可以来自任何一个学期。也就是说,“B1”与“F1”和“S1”都是相同的,或者全年的第一节课程适用于秋季学期的第一学期和春季学期的第一学期。

(理想情况下,我还想双重检查课程的年龄范围与学生的年龄是否匹配,跳过学生不符合资格参加的课程。学生缩写后的两位数字是学生在秋季学期开始时的年龄。然而,大多数学生没有在其年龄范围外投票,所以我可以手动清理这一点。)

如果此问题以前已经提出,我由衷道歉,但我对尝试弄清楚这个问题感到如此纠结,以至于我甚至不知道如何正确地表达我的搜索!如果已经解决了这个问题,我将非常感谢您指向解决方案。

我的Google表格(已将身份数据替换为随机信息):https://docs.google.com/spreadsheets/d/1RLkwrZPFss2ALv006aRvMwuGLQCN1l7OiSDCL70dYQ0/edit?usp=sharing

英文:

My brain hurts trying to figure this out, but I know there is a way.

I am trying to write a formula that does the following: For each Schedule-tab cell (that is, for each student and class period), search through the Survey-tab column that corresponds to the student's column to find the first class that is both ranked 6 and matches the class period and return both the ranking and the class name (from Survey-tab column B), if none is found, then search for the first class ranked 5, then for one ranked 4, then ranked 3, and if nothing is found, return "NO MATCH."

A complicating factor is that classes can be are either semester length or full year (both semesters), so a semester match could be from either. That is "B1" is the same as both "F1" and "S1" or a Full-Year First-Period Class is a match for both Fall Semester First Period and Spring Semester First Period.

(Ideally, I'd also like to double check the class's age range against the student's age and skip any classes the student is not eligible to take. The two digits after the student's initials are the student's age at the start of Fall semester. However, most students did not vote outside their age range, so I can clean that up manually.)

I apologize sincerely if this question has been asked before, but my brain is so twisted about trying to figure this out that I don't even know how to correctly phrase my search! If this has been addressed, I would very much appreciate being pointed toward the solution.

My Google Sheet (with identifying data replaced with random information): https://docs.google.com/spreadsheets/d/1RLkwrZPFss2ALv006aRvMwuGLQCN1l7OiSDCL70dYQ0/edit?usp=sharing

I tried INDEX and MATCH and REGEXMATCH and a few other things trying to make this happen, but I've never done anything so complicated before, and honestly, my attempts were too embarrassingly wrong to be worth sharing! But the real problem is that I deleted everything in a fit of frustration (before remembering that I could ask for help).

答案1

得分: 1

已添加解决方案到您的表格中。请验证结果,确保它正确提取了结果。

=makearray(counta(A2:A13),counta(E1:AU1),lambda(r,c,ifna(let(a,sortn(filter(filter('Course Interest Survey'!A2:AS,('Course Interest Survey'!A1:AS1=index(E1:AU1,,c))+('Course Interest Survey'!A1:AS1="Classes")),('Course Interest Survey'!C2:C=index(A2:A13,r))+('Course Interest Survey'!C2:C=index(B2:B13,r))),1,,2,0),ifs(index(a,,2)>2,index(a,,2)&": "&index(a,,1),index(a,,2)<3,"NO MATCH")),"none scheduled"))

尝试找到符合复杂条件的匹配项。

英文:

Added solution to your sheet here. Please do validate the results to make sure its pulling the results aptly.

=makearray(counta(A2:A13),counta(E1:AU1),lambda(r,c,ifna(let(a,sortn(filter(filter(&#39;Course Interest Survey&#39;!A2:AS,(&#39;Course Interest Survey&#39;!A1:AS1=index(E1:AU1,,c))+(&#39;Course Interest Survey&#39;!A1:AS1=&quot;Classes&quot;)),(&#39;Course Interest Survey&#39;!C2:C=index(A2:A13,r))+(&#39;Course Interest Survey&#39;!C2:C=index(B2:B13,r))),1,,2,0),ifs(index(a,,2)&gt;2,index(a,,2)&amp;&quot;: &quot;&amp;index(a,,1),index(a,,2)&lt;3,&quot;NO MATCH&quot;)),&quot;none scheduled&quot;)))

尝试找到符合复杂条件的匹配项。

答案2

得分: 0

另一个有效的解决方案,除了将“none scheduled”标记为“no match”(在这种情况下,我们只有一个没有安排的课程时段,所以我可以解决这个问题)。在这里分享一下,以防对面临相同问题的人更合适。

这使用FILTER来查找匹配项,然后使用ARRAY_CONSTRAIN来限制筛选结果为第一个匹配项。

=ARRAY_CONSTRAIN(IFERROR(FILTER("6: " & 'Course Interest Survey'!$B$2:$B$50,('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$A2)+('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$B2),'Course Interest Survey'!D$2:D$50=6),IFERROR(FILTER("5: " & 'Course Interest Survey'!$B$2:$B$50,('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$A2)+('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$B2),'Course Interest Survey'!D$2:D$50=5),IFERROR(FILTER("4: " & 'Course Interest Survey'!$B$2:$B$50,('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$A2)+('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$B2),'Course Interest Survey'!D$2:D$50=4),IFERROR(FILTER("3: " & 'Course Interest Survey'!$B$2:$B$50,('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$A2)+('Course Interest Survey'!$C$2:$C$50='Course Schedule'!$B2),'Course Interest Survey'!D$2:D$50=3),"NO MATCH"))),1,1)

英文:

Another solution that works well enough except for marking "none scheduled" as "no match" (in this case, we only have one class period with nothing scheduled, so I can work around that). Sharing it here in case it's a better fit for someone facing the same problem.

This uses FILTER to find matches and then ARRAY_CONSTRAIN to limit the filtered results to the first match.

=ARRAY_CONSTRAIN(IFERROR(FILTER(&quot;6: &quot; &amp; &#39;Course Interest Survey&#39;!$B$2:$B$50,(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$A2)+(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$B2),&#39;Course Interest Survey&#39;!D$2:D$50=6),IFERROR(FILTER(&quot;5: &quot; &amp; &#39;Course Interest Survey&#39;!$B$2:$B$50,(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$A2)+(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$B2),&#39;Course Interest Survey&#39;!D$2:D$50=5),IFERROR(FILTER(&quot;4: &quot; &amp; &#39;Course Interest Survey&#39;!$B$2:$B$50,(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$A2)+(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$B2),&#39;Course Interest Survey&#39;!D$2:D$50=4),IFERROR(FILTER(&quot;3: &quot; &amp; &#39;Course Interest Survey&#39;!$B$2:$B$50,(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$A2)+(&#39;Course Interest Survey&#39;!$C$2:$C$50=&#39;Course Schedule&#39;!$B2),&#39;Course Interest Survey&#39;!D$2:D$50=3),&quot;NO MATCH&quot;)))),1,1)

huangapple
  • 本文由 发表于 2023年3月7日 23:40:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75664087.html
匿名

发表评论

匿名网友

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

确定