google-sheets - 第 1 列的最大值,其中第 2 列的值匹配某些条件
问题描述
假设我在表格中有以下内容:
A | B | desired_output
----------------------------
1 | 10 | 1 | 0
2 | 20 | 7 | 0
3 | 30 | 3 | 0
4 | 20 | 2 | 0
5 | 30 | 5 | 1
我想为desired_output
列中的每个单元格找到一个公式,该公式查看 B1:B5 的最大值,但仅适用于 A = max(A1:A5) 的行
如果不清楚,我会尝试换一种说法:
for all the rows in A1:A5 that are equal to max(A1:A5) // so that's rows 3 and 5
find the one which has the max value on B // so between B3 and B5, that's B5
output 1 for this one, 0 for the other
如果存在这样的功能,我会说会有一个where
地方,就像= if(B=(max(B1:B5) where A = max(A1:A5)), 1, 0)
但我找不到如何去做......
我可以用一个技巧在两列中做到这一点:
A | B | C | D
----------------------------
1 | 10 | 1 | | 0
2 | 20 | 7 | | 0
3 | 30 | 3 | 3 | 0
4 | 20 | 2 | | 0
5 | 30 | 5 | 5 | 1
Cn = if(An=max(A$1:A$5),Bn,"")
和_Dn = if(Cn = max(C$1:C$5), 1, 0)
但我仍然无法在一栏中找到如何做到这一点
解决方案
=ARRAYFORMULA(IF(LEN(A1:A), IF(IFERROR(VLOOKUP(CONCAT(A1:A&"×", B1:B),
JOIN("×", QUERY(A1:B, "order by A desc, B desc limit 1")), 1, 0), )<>"", 1, 0), ))
或更短:
=ARRAYFORMULA(IF(A:A<>"",N(A:A&"×"&B:B=JOIN("×",SORTN(A:B,1,,1,0,2,0))),))
=ARRAYFORMULA(IF(A:A<>"",N(A:A&B:B=JOIN(,SORTN(A:B,1,,1,0,2,0))),))
推荐阅读
- firebase - Promise.all 不等待使用 Firebase 数据库解决的承诺数组
- django - 如何使用 WSGI 在 Bluehost 上部署 Django 应用程序?
- c - 如何使用 gdb 以十六进制打印文件的内容?
- python-2.7 - Scrapy在10张图片后返回Image Url的Base64
- c# - 为什么不能添加int类型的对象和数字?
- reactjs - ReactJS:过滤图像以映射到轮播
- javascript - 以角度从字符串中删除特殊字符
- llvm - 获取 Halide 的 Tiramisu 子模块 llvm 失败,出现 .//3rdParty/llvm: No such file or directory 错误
- dart - 在飞镖中使用 fromJson 扩展
- mysql - 在 laravel 中加入 case 和 when 语句