You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Excel公式需求:查找最新1之前的最后一个非1值

Solution to Find the Last Non-1 Value Before the Latest Occurrence of 1

Got it, let's work through this problem step by step. The issue with your initial formula MATCH(MIN(range),range,0)+1 is that it only targets the first occurrence of the minimum value (1), but we need to focus on the last occurrence of 1 instead, then locate the nearest non-1 value right before it.

Solutions tailored to your Excel version:


1. For Excel 365/2021 (Simplest: XLOOKUP)

If you have access to XLOOKUP, this formula is clean and intuitive. Assume your data lives in range A1:A10:

=XLOOKUP(FALSE, A1:INDEX(A:A, MATCH(1, A:A, 1))=1, A1:INDEX(A:A, MATCH(1, A:A, 1)),, 0, -1)

How it works:

  • MATCH(1, A:A, 1): Finds the row number of the last occurrence of 1. The 1 as the third argument tells MATCH to search for the largest value ≤ 1, which lands on the final 1 (since 1 is your minimum value).
  • A1:INDEX(A:A, MATCH(...)): Truncates your data range to include everything from the start up to that final 1.
  • XLOOKUP(FALSE, [truncated range]=1, [truncated range],, 0, -1): Searches backwards (via the -1 argument) through the truncated range to find the first cell that isn't 1—this is exactly the last non-1 value before the final 1.

2. For Older Excel Versions (Array Formula)

If you're using an older Excel version without XLOOKUP support, use this array formula (remember to press Ctrl+Shift+Enter after typing it, not just Enter):

=INDEX(A:A, MAX(IF(A1:INDEX(A:A, MATCH(1, A:A, 1))<>1, ROW(A1:INDEX(A:A, MATCH(1, A:A, 1))))))

How it works:

  • Same MATCH(1, A:A, 1) to get the final 1's position.
  • IF(A1:INDEX(...)<>1, ROW(...)): Creates an array where non-1 cells are replaced with their row numbers, and 1 cells return FALSE.
  • MAX(...): Grabs the largest row number from that array (this corresponds to the last non-1 cell before the final 1).
  • INDEX(A:A, ...): Pulls the value from that row.

3. Alternative with LOOKUP (No Array Entry Required)

Another option that works in most Excel versions without needing array entry:

=LOOKUP(2, 1/(A1:INDEX(A:A, MATCH(1, A:A, 1))<>1), A1:INDEX(A:A, MATCH(1, A:A, 1)))

How it works:

  • 1/(A1:INDEX(...)<>1): Generates an array where non-1 cells become 1 and 1 cells become #DIV/0! errors (which LOOKUP automatically ignores).
  • LOOKUP(2, 1/..., [range]): LOOKUP searches for the largest value ≤ 2 (which is the last 1 in the error-free array) and returns the corresponding value from your data range.

Example Adjustment for Your Specific Scenario

You mentioned your example should return 3 instead of 4—this suggests you might be looking for the last non-1 value before the first occurrence of 1 (not the last one). In that case, swap MATCH(1, A:A, 1) with MATCH(1, A:A, 0) (which finds the first 1) and adjust the range to stop just before that first 1:

=XLOOKUP(FALSE, A1:INDEX(A:A, MATCH(1, A:A, 0)-1)=1, A1:INDEX(A:A, MATCH(1, A:A, 0)-1),, 0, -1)

For a sample range like [2, 3, 1, 4, 1], this formula will return 3 as expected.

内容的提问来源于stack exchange,提问作者user1627466

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:57:56