Excel: counting the "either or" occurrence of multiple criteria in column B while not double-counting duplicates in column A

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

Excel: counting the "either or" occurrence of multiple criteria in column B while not double-counting duplicates in column A

问题

这里是一些我生成的示例Excel数据,用于描述我面临的问题。

学生ID 科目 课程名称
001 数学 代数 I
002 科学 生物学
002 数学 代数 II
002 历史 美国历史
003 数学 几何学
003 科学 化学
004 英语 剧本写作
004 数学 三角学
004 语言 西班牙语 I
004 语言 意大利语 I
005 英语 剧本写作
005 英语 演讲写作
006 语言 语言学
006 科学 物理学
006 英语 修辞学
007 语言 西班牙语 II
007 数学 预备计算
008 历史 世界历史
008 语言 法语 I
008 英语 神话学
009 英语 诗歌
  • 每列都使用字符串数据类型

我正在努力找出一个Excel函数/公式,可以计算正在修读数学或科学课程的不同学生人数,但确保只计算每位学生一次。所以对于上述示例数据,有6名不同的学生修读了数学或科学课程。

我在网上找到的大部分信息都与我想要的不完全相符。在像Python这样的语言中,这个问题较为简单(您可以按科目筛选,然后去重学生ID),但由于我对Excel函数的细节不太熟悉,所以一直在努力。

我尝试过使用各种Excel函数,如COUNTIFS和SUMPRODUCT,但没有取得太大进展,目前还没有找到解决方案。

非常感谢您的帮助!如果需要任何澄清,请告诉我。

英文:

Here's some sample excel data that I spun up to describe the problem that I'm facing.

StudentID Subject ClassName
001 Math Algebra I
002 Science Biology
002 Math Algebra II
002 History US History
003 Math Geometry
003 Science Chemistry
004 English Playwriting
004 Math Trigonometry
004 Language Spanish I
004 Language Italian I
005 English Playwriting
005 English Speech Writing
006 Language Linguistics
006 Science Physics
006 English Rhetoric
007 Language Spanish II
007 Math Pre-Calculus
008 History World History
008 Language French I
008 English Mythology
009 English Poetry
  • Every column uses the string data type

I'm struggling to figure out an excel function/formula that will count how many distinct students are taking either a Math or Science course but making sure to only count each student once. So for the above example data, there are 6 distinct students who took either a Math or Science course.

Most of the information I've found online has solutions that are related to but not exactly what I want. This problem is simpler in a language like Python (where you can filter by subject and then de-duplicate the StudentID) but I'm having a hard time since I'm not super familiar with the nitty-gritty of excel functions.

I've tried playing around with various excel functions like countifs and sumproduct but haven't made much progress and nothing has worked so far.

Any help would be greatly appreciated! Please let me know if any clarifications would be helpful.

答案1

得分: 1

尝试使用以下公式:


• 单元格<kbd>E2</kbd>中使用的公式:

=ROWS(UNIQUE(FILTER(A2:A22,ISNUMBER(XMATCH(B2:B22,{"数学","科学"})))))

另一种替代方法使用<kbd>MMULT( )</kbd>


• 单元格<kbd>E2</kbd>中使用的公式:

=ROWS(UNIQUE(FILTER(A2:A22,MMULT(N(B2:B22={"数学","科学"}),{1;1}))))

英文:

Try using the following formula:

Excel: counting the "either or" occurrence of multiple criteria in column B while not double-counting duplicates in column A


• Formula used in cell <kbd>E2</kbd>

=ROWS(UNIQUE(FILTER(A2:A22,ISNUMBER(XMATCH(B2:B22,{&quot;Math&quot;,&quot;Science&quot;})))))

Another alternative using <kbd>MMULT( )</kbd>

Excel: counting the "either or" occurrence of multiple criteria in column B while not double-counting duplicates in column A


• Formula used in cell <kbd>E2</kbd>

=ROWS(UNIQUE(FILTER(A2:A22,MMULT(N(B2:B22={&quot;Math&quot;,&quot;Science&quot;}),{1;1}))))

huangapple
  • 本文由 发表于 2023年7月28日 02:59:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76782699.html
匿名

发表评论

匿名网友

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

确定