Excel:计算 B 列中多个条件的“非此即彼”出现次数,而不对 A 列中的重复项进行重复计算

问题描述 投票:0回答:1

这里有一些示例 Excel 数据,我用它们来描述我面临的问题。

   |     A     |    B     |       C        | 
   +-----------+----------+----------------+ 
1  | StudentID | Subject  |   ClassName    |
   +-----------+----------+----------------+
2  | 001       | Math     | Algebra I      |
3  | 002       | Science  | Biology        |
4  | 002       | Math     | Algebra II     |
5  | 002       | History  | US History     |
6  | 003       | Math     | Geometry       |
7  | 003       | Science  | Chemistry      |
8  | 004       | English  | Playwriting    |
9  | 004       | Math     | Trigonometry   |
10 | 004       | Language | Spanish I      |
11 | 004       | Language | Italian I      |
12 | 005       | English  | Playwriting    |
13 | 005       | English  | Speech Writing |
14 | 006       | Language | Linguistics    |
15 | 006       | Science  | Physics        |
16 | 006       | English  | Rhetoric       |
17 | 007       | Language | Spanish II     |
18 | 007       | Math     | Pre-Calculus   |
19 | 008       | History  | World History  |
20 | 008       | Language | French I       |
21 | 008       | English  | Mythology      |
22 | 009       | English  | Poetry         |

* Every column uses the string data type

我正在努力找出一个Excel函数/公式来计算有多少不同的学生正在学习数学或科学课程,但确保只计算每个学生一次。因此,对于上面的示例数据,有 6 个不同的学生 选修了数学或科学课程。

我在网上找到的大多数信息都有与我想要的相关但不完全是我想要的解决方案。这个问题在像Python这样的语言中更简单(你可以按主题过滤,然后删除重复的StudentID),但我遇到了困难,因为我不太熟悉excel函数的本质。

我尝试过使用各种 Excel 函数,如 countifs 和 sumproduct,但没有取得太大进展,到目前为止没有任何效果。

任何帮助将不胜感激!如果任何澄清有帮助,请告诉我。

excel excel-formula countif
1个回答
0
投票

尝试使用以下公式:


• 单元格中使用的公式 E2

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

使用 MMULT( )

的另一种选择


• 单元格中使用的公式 E2

=SUM(N(UNIQUE(FILTER(A2:A22,
     MMULT(N(B2:B22={"Math","Science"}),{1;1})))<>""))

© www.soinside.com 2019 - 2024. All rights reserved.