英文:
Is it possible to sum all weighted values without adding helper columns?
问题
我已经设置了以下两个表格:
一个调查问题的表格
分组 | 问题 | 权重 |
---|---|---|
G1 | Q1 | 0.4 |
G1 | Q2 | 0.3 |
G1 | Q3 | 0.3 |
G2 | Q4 | 0.5 |
G2 | Q5 | 0.5 |
G3 | Q6 | 0.8 |
G3 | Q6 | 0.1 |
G3 | Q7 | 0.1 |
实际上它有更多的问题,但这应该足够演示了。
此外,我还有一个包含所有答案和“受访者”(每个受访者回答关于N个受访对象的每个问题)的表格:
受访对象 | 问题 | 得分 |
---|---|---|
S1 | Q1 | 9 |
S1 | Q2 | 8 |
S1 | Q3 | 11 |
... | ... | ... |
Sn | Q7 | 4 |
现在... 我通常会在响应表(最后一个表格)中添加一个xlookup/index-match列,以获取每个权重,将其与得分相乘,然后从那里开始工作。
然而,我想知道是否有一种更优雅的解决方案,不需要这样做。
我想要的是有一个表格,它通过以下方式总结数据:
- 将每个问题与其权重相乘(使用某种查找)
- 按受访对象和分组分组(并求和值)
- 在以下表格中呈现:
X | S1 | S2 | S3 | ... | Sn |
---|---|---|---|---|---|
G1 | 计算 | 计算 | 计算 | 计算 | 计算 |
G2 | 计算 | 计算 | 计算 | 计算 | 计算 |
G3 | 计算 | 计算 | 计算 | 计算 | 计算 |
最好使用一个公式。我认为通过使用filter函数、xlookup或类似的函数,这应该是可能的,但是我在我的尝试和搜索过程中都受阻了。
提前感谢您。
编辑:尝试了下面的方法。对于第1组中的问题,我得到了正确的值,但对于其他组却是0。我检查了在a、b、c、d中产生的矩阵,它们如下:
a:
b:
c:
d:
我相信问题出在SUM(IFERROR(d*c;0)),因为在这个例子中,c的前3行都是错误的,而d只在前3行中有值,所以它们将为0,当c达到其值时,d已经用完了。
示例工作簿链接:
工作簿
英文:
I have the following two tables set up:
A table of survey questions
Group | Question | Weight |
---|---|---|
G1 | Q1 | 0.4 |
G1 | Q2 | 0.3 |
G1 | Q3 | 0.3 |
G2 | Q4 | 0.5 |
G2 | Q5 | 0.5 |
G3 | Q6 | 0.8 |
G3 | Q6 | 0.1 |
G3 | Q7 | 0.1 |
In reality it has a lot more questions, but this should be enough for demonstration purposes.
In addition I have a table with all the answers and "subjects" (each respondent answers each question concerning N subjects):
Subject | Question | Score |
---|---|---|
S1 | Q1 | 9 |
S1 | Q2 | 8 |
S1 | Q3 | 11 |
... | ... | ... |
Sn | Q7 | 4 |
Now.. what I would normally do is add an xlookup/index-match column to the response-table (last one) to pull each weight, multiply with the score, and then work from there.
I wonder, however, if there is a more elegant solution that does not require this.
What I want is to have a table that does summarizes the data by
- multiply each question by its weight (using some lookup)
- group by subject and group (and sum values)
- Present in following table:
X | S1 | S2 | S3 | ... | Sn |
---|---|---|---|---|---|
G1 | calc | calc | calc | calc | calc |
G2 | calc | calc | calc | calc | calc |
G3 | calc | calc | calc | calc | calc |
Preferably in one formula. I think this should be possible by using the filter function, xlookup, or similar, but I have been stumped in both my own attempts and by my googling skills.
Thanks in advance..
Edit: Tried the below method. I get correct values for questions in group 1, but 0 for the others. I inspected the matrices produced in a, b, c, d there and they are as follows:
a:
b:
c:
d:
I believe the problem occurs in the SUM(IFERROR(d*c;0)), because in this example the first 3 rows of c are all errors, and the d only has values in the first 3 rows, so those will be 0, and when c gets to its values, d has run out.
Link to example workbook:
Workbook
答案1
得分: 2
如果我没弄错的话,这应该对你有用,使用<kbd>FILTER( )</kbd>函数。
• 单元格<kbd>J2</kbd>中使用的公式:
=LET(
a,FILTER($B$2:$C$9,$A$2:$A$9=$I2),
b,FILTER($F$2:$G$6,J$1=$E$2:$E$6),
c,INDEX(TAKE(a,,-1),XMATCH(TAKE(b,,1),TAKE(a,,1))),
d,INDEX(TAKE(b,,-1),XMATCH(TAKE(a,,1),TAKE(b,,1))),
SUM(IFERROR(d*c,0)))
英文:
If i am not wrong this should work for you, using <kbd>FILTER( )</kbd> Function
• Formula used in cell <kbd>J2</kbd>
=LET(
a,FILTER($B$2:$C$9,$A$2:$A$9=$I2),
b,FILTER($F$2:$G$6,J$1=$E$2:$E$6),
c,INDEX(TAKE(a,,-1),XMATCH(TAKE(b,,1),TAKE(a,,1))),
d,INDEX(TAKE(b,,-1),XMATCH(TAKE(a,,1),TAKE(b,,1))),
SUM(IFERROR(d*c,0)))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论