基于同一行多个标准的 Excel 计数/求和

发布于 2025-01-09 10:58:46 字数 1332 浏览 3 评论 0原文

我有一个相对简单的问题,但我却被难住了——也许是新冠病毒带来的脑雾。我会尽力解释这个问题。

这是一个模拟数据集:

    A   B   C   D   E   F   G   H   I   J   K   L   M   N
1   X1  X2  X3  Y1  Y2  Y3  X1  X2  X3  X1  X2  X3  Ct  St
2   1   2   0.2             0   2   0.5 1   2   0.1 2   0.3
3   1   2   0.3             1   1   0.2             1   0.3
4   1   2   0.6 1   2   0.1                         1   0.6
5   1   2   1.1                 2   0.7 1       0.5 1   1.1

AN 反映列名称,而第一列 (1-5) 反映 Excel 中的行名称。

每列都被标记为 X(例如,男性)和 Y(例如,女性)。男性有 3 个特征(X1、X2、X3),女性有 3 个特征(Y1、Y2、Y3)。我们可以将相邻列视为属于一个性状(例如,A、B 和 C 列中的 X1、X2 和 X3 构成性状 1 的一组男性特征;G、H 和 I 列中的 X1、X2 和 X3形成一组相似的特征,但特征 2 等)。

对于每一行,我想根据一组条件计算总数(Ct,请参阅 M 列)和总和(St,请参阅 N 列)。

总数:计算 X1 为“1”、X2 为“2”的男性 (X) 特征的数量,给出“总数”。

总和:将 X3 值与 X2 为“2”的男性 (X) 性状相加,得出“总和”。

我手动计算了每列的计数总计和总和,以使这些定义更加清晰。在第 1 行中,有两个性状满足计数总计标准 (Ct = 2),其中它们的 X1 值 = 1 且 X2 值 = 2。请注意,虽然 H 列中的 X2 值符合条件 (X2 = 2),但 H 列中的 X1 值符合条件。 G 列不等于 1,因此不计算在内。此外,我们仅将性状 1 和 2 的 X3 值相加(例如,C 列中的 X3 和 L 列中的 X3),总计为 0.3 (0.2 + 0.1)。

公式应忽略符合条件但适用于女性特征的值集(例如,参见第 3 行),并且应该适用于缺失值(例如,在 J 列,第 4 行中,X1 缺失,因此无法计算,即使 X2在 K 列中,第 4 行的限定值为 2)。

我希望这是有道理的。

我的本能是使用 SUMPRODUCT 公式,但我正在努力整合这两个条件,例如,对于每一行:

=SUMPRODUCT(((A1:L1="X1")*(A2:L2=1))*((A1:L1="X2")*(A2:L2=2)))

任何指导将不胜感激。

I have a relatively simple problem which I am getting stumped on - perhaps it is this brain fog from Covid. I'll try my best to explain the problem.

Here is a simulated dataset:

    A   B   C   D   E   F   G   H   I   J   K   L   M   N
1   X1  X2  X3  Y1  Y2  Y3  X1  X2  X3  X1  X2  X3  Ct  St
2   1   2   0.2             0   2   0.5 1   2   0.1 2   0.3
3   1   2   0.3             1   1   0.2             1   0.3
4   1   2   0.6 1   2   0.1                         1   0.6
5   1   2   1.1                 2   0.7 1       0.5 1   1.1

A-N reflects the column names while the first column (1-5) reflects the row names in Excel.

Each column has been labelled as either X (e.g., male) and Y (e.g., female). There are three characteristics for male (X1, X2, X3) and three characteristics for female (Y1, Y2, Y3). We can think of adjacent columns as belonging to a trait (e.g., X1, X2, and X3 in columns A, B and C form a set of male characteristics for trait 1; X1, X2, and X3 in columns G, H and I form a set of similar characteristics but for trait 2, etc.).

For each row, I would like to calculate a count total (Ct, see column M) and sum total (St, see column N) based on a set of conditions.

Count total: Count the number of male (X) traits that feature a "1" for X1 and "2" for X2, giving a 'count total'.

Sum total: Sum the X3 values over male (X) traits that feature a "2" for X2, giving a 'sum total'.

I have manually calculated the count totals and sum totals for each column to make these definitions clearer. In row 1, there are two traits that fulfil the count total criteria (Ct = 2), whereby their X1 values = 1 and X2 values = 2. Notice that while the X2 value in column H qualifies (X2 = 2), X1 in column G is not equal to 1, so it is not counted. Furthermore, we only sum the X3 values for traits 1 and 2 (e.g., X3 in Column C and X3 in Column L), giving us a total of 0.3 (0.2 + 0.1).

The formulae should ignore sets of values that qualify but are for female traits (e.g., see row 3) and should work across missing values (e.g., in col J, row 4, X1 is missing, so it cannot be counted, even if X2 in col K row 4 features a qualifying value of 2).

I hope that makes sense.

My instinct was to use a SUMPRODUCT formula, but I am struggling to integrate the two conditions, e.g., for each row:

=SUMPRODUCT(((A1:L1="X1")*(A2:L2=1))*((A1:L1="X2")*(A2:L2=2)))

Any guidance would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的她 2025-01-16 10:58:46

我还没有彻底检查过这一点,但建议将 Ct

=SUMPRODUCT((A$1:J$1="X1")*(A2:J2=1)*(B$1:K$1="X2")*(B2:K2=2))

和 St

=SUMPRODUCT((A$1:J$1="X1")*(A2:J2=1)*(B$1:K$1="X2")*(B2:K2=2)*(C$1:L$1="X3")*C2:L2)

抄下来。

输入图片此处描述

I haven't checked this thoroughly, but suggest for Ct

=SUMPRODUCT((A$1:J$1="X1")*(A2:J2=1)*(B$1:K$1="X2")*(B2:K2=2))

and for St

=SUMPRODUCT((A$1:J$1="X1")*(A2:J2=1)*(B$1:K$1="X2")*(B2:K2=2)*(C$1:L$1="X3")*C2:L2)

copied down.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文