excel - 如何连续获得前 n 个非零值?
问题描述
我目前有这个公式,但它以我想要的相反顺序返回非零值。
这是公式:
=INDEX($R275:$BE275,LARGE(IF($R275:$BE275<>0,COLUMN($R275:$BE275)- MIN(COLUMN($R275:$BE275))+1),COLUMNS($A:A)))
当我希望它以另一种方式工作时,这将返回 BE 列中的第一个非零值,即从右到左的第一个实例。当我在右边起草公式时,我希望它从右到左拾取下一个非零值。
如果我能弄清楚这一点,以及如何返回列标题,那就太好了。
解决方案
Screenshot/here refer.
The formula you provided returns the last non-zero value which is also what you state you're trying to find:
"I want...the first instance from right to left."
To avoid ambiguity, I provide solutions for the first such occurrence (and corresponding heading), and a revised method to determine the last occurrence (or first occurrence "from right to left").
First occurrence (working from left to right)
Function can be simplified significantly to the following:
=INDEX(A2:H2,0,MATCH(1,--(A2:H2<>0),0))
Corresponding heading:
=INDEX($A$1:$H$1,0,MATCH(1,--(A2:H2<>0),0))
Per @ScottCraner, this also works (albeit uses the same unnecessarily long function):
=INDEX($R275:$BE275,SMALL(IF($R275:$BE275<>0,COLUMN($R275:$BE275)- MIN(COLUMN($R275:$BE275))+1),COLUMNS($A:A)))
Last occurrence
Revised function to consider (requires Office 365 compatible version of Excel, and customisation to return corresponding heading)..
=LET(reverse,INDEX(A2:H2,0,SEQUENCE(1,COUNTA(A2:H2),COUNTA(A2:H2),-1)),INDEX(reverse,MATCH(1,--(reverse<>0),0)))
推荐阅读
- excel - 如何根据当前工作表路径进行合并
- sql - 如何覆盖此函数以将数据存储在数据库中?
- if-statement - 如何从具有不同字数的异构变量中提取中间名?
- reactjs - Highcharts-React 返回 Object 并且 React 给出错误 - React.createElement: type is invalid
- python - 使用串行连接进行控制时,如何使用 arduino 控制 bldc 电机?
- java - 由于“插件 uBlock0@raymondhill.net 未正确签名”,Selenium 未安装 Firefox 插件
- html - 离子选择无法使用动态值正确渲染?离子 4
- scala - 计算列表中的连续字符?
- gpu - Numba 中的组合矢量化函数
- visual-studio - MS Unity 在初始化后立即失败