我在excel中有一个名为tableName
的表格,如下所示:
ColumnA ColumnB
1111 aaaa
1111 bbbb
1111 aaaa
1111 cccc
1111 aaaa
1111 aaaa
1111 aaaa
2222 aaaa
2222 aaaa
2222 ffff
2222 aaaa
2222 aaaa
3333 bbbb
3333 bbbb
4444 aaaa
4444 bbbb
我已经得到了这个(在单元格B2
中):
{=SUM(IF((tableName[ColumnB]=B$1)*1;1/COUNTIFS(tableName[ColumnA];tableName[ColumnA];tableName[ColumnB];B$1)))}
单元格aaaa
中的B1
用于计算ColumnA
ColumnB
中aaaa
包含ColumnA ColumnB
1111 aaaa <----is counted lets call it 1
1111 bbbb <--------not counted because ColumnB isn't aaaa
1111 aaaa <----not counted because duplicate of 1
1111 cccc <--------not counted because ColumnB isn't aaaa
1111 aaaa <----not counted because duplicate of 1
1111 aaaa <----not counted because duplicate of 1
1111 aaaa <----not counted because duplicate of 1
2222 aaaa <----is counted lets call it 2
2222 aaaa <----not counted because duplicate of 2
2222 ffff <--------not counted because ColumnB isn't aaaa
2222 aaaa <----not counted because duplicate of 2
2222 aaaa <----not counted because duplicate of 2
3333 bbbb <--------not counted because ColumnB isn't aaaa
3333 bbbb <--------not counted because ColumnB isn't aaaa
4444 aaaa <----is counted lets call it 3
4444 bbbb <--------not counted because ColumnB isn't aaaa
的不同值。这里的结果是3(1111和2222和4444),标记的列被计算在内:
bbbb
现在我在单元格A2
中有ColumnA
并希望计算相同数量,但A2
和{{1}中必须有另一行具有相同的值ColumnB
中的(= bbbb)。
ColumnA ColumnB
1111 aaaa <----is counted because x exists
1111 bbbb <--------this is x
1111 aaaa
1111 cccc
1111 aaaa
1111 aaaa
1111 aaaa
2222 aaaa <----not counted because no pair (2222, bbbb) exists
2222 aaaa
2222 ffff
2222 aaaa
2222 aaaa
3333 bbbb
3333 bbbb
4444 aaaa <----is counted because y exists
4444 bbbb <--------this is y
我不知道该怎么做。
我的完整目标是创建一个列联表:
aaaa bbbb cccc ffff
aaaa 3 2 1 1
bbbb 2 3 1 0
cccc 1 1 1 0
ffff 1 0 0 1