简体   繁体   English

LOOKUP公式的最后一个评估步骤后面的逻辑,用于查找行中的最后一个非空值。

[英]Logic behind last evaluation step of a LOOKUP formula to find last non empty value in a row.

I want to get last non empty cell from every row for further operations. 我想从每一行中获取最后一个非空单元格,以进行进一步的操作。 Searching Net I came across a LOOKUP formula which can do this job fine. 搜索网络时,我遇到了一个LOOKUP公式,可以很好地完成此工作。 I have alpha as well as numeric data in the rows. 我在行中有alpha以及数字数据。 Sample Data is shown below. 示例数据如下所示。

ID1 ID2 ID3 ID4 ID5     ID6 ID7 ID8 ID9 ID10    ID11
a1  a2  a3  a4  a5      23  24  25      25  

23  NN  67  99  200001  ss  p1  23  rq          3

I am using the following formula in L4 which gives correct results that is 3 in L4. 我在L4中使用以下公式,该公式给出的正确结果在L4中为3。 Similar formula for row 2 gives result of 25 in L2. 第2行的类似公式得出L2中的结果为25。 To understand the formula I carried out Formula Evaluation but I am not getting the logic of last step as how it translates to final result. 为了理解该公式,我进行了“公式评估”,但是我不了解最后一步的逻辑,因为它如何转换为最终结果。

=LOOKUP(2,1/(A4:K4<>""),A4:K4)

LOOKUP(2,{1,1,1,1,1,1,1,1,1,#DIV/0!,1},A4:K4) After this step result that is the last non empty value of Row 4 comes ie 3 Can someone explain how this line is finally translating into the result step by step. LOOKUP(2,{1,1,1,1,1,1,1,1,1,#DIV / 0!,1},A4:K4)在此步骤之后的结果是第4行的最后一个非空值3有人可以解释这条线最终将如何逐步转化为结果。

快照

Basically taking the below formula as an example 基本上以以下公式为例

=LOOKUP(2,1/(A1:D1<>""),A1:D1)

With data in A1:D1 在A1:D1中有数据

A1  B1  C1  D1
1    2   3  

The formula will populate as follows 该公式将填充如下

=LOOKUP(2,{1,1,1,#DIV/0!},{1,2,3,0})

The way this works is quite simple. 它的工作方式非常简单。

1/(A1:D1<>"") creates an array of 1's and #DIV\\0! 1 /(A1:D1 <>“”)创建一个由1和#DIV \\ 0组成的数组!

            1  where the cell is not blank
            #DIV/0  where the cell is blank

Then the lookup formula looks for a 2 in this array , which it cant find, but it will always return the position of then last NON ERROR value in the context of an array filled with 1's and #DIV/0!, which would be the 3rd position in the array, The LOOKUP formula then returns the 3rd position of the last argument array in the formula A1:D1 , which is 3 然后,查找公式在此数组中查找2,但找不到,但是在填充有1和#DIV / 0!的数组的上下文中,它将始终返回最后一个NON ERROR值的位置,即数组中的第3个位置,LOOKUP公式然后返回公式A1:D1中最后一个参数数组的第3个位置,即3

This approach finding the last filled cell uses the vector form of LOOKUP . 这种查找最后一个填充单元格的方法使用LOOKUP的矢量形式。 In

=LOOKUP(2,{1,1,1,1,1,1,1,1,1,#DIV/0!,1},A4:K4) the 2 is the lookup_value, the array {1,1,1,1,1,1,1,1,1,#DIV/0!,1} is the lookup_vector and the A4:K4 is the result_vector. =LOOKUP(2,{1,1,1,1,1,1,1,1,1,#DIV/0!,1},A4:K4) 2是lookup_value,数组{1,1,1,1,1,1,1,1,1,#DIV/0!,1}是lookup_vector,而A4:K4是result_vector。

The vector form of LOOKUP looks in a lookup_vector for the lookup_value and returns the value from the same position in the result_vector. LOOKUP的向量形式在lookup_vector中查找lookup_value,并从result_vector中相同位置返回值。

If the LOOKUP function can't find the lookup_value directly in the lookup_vector, the function matches the largest value in lookup_vector that is less than or equal to lookup_value. 如果LOOKUP函数无法直接在lookup_vector中找到lookup_value,则该函数将匹配lookup_vector中小于或等于lookup_value的最大值。 If multiple equal values are in the array, which are the largest which are less than or equal to lookup_value, the position of the last is taken. 如果数组中有多个相等的值,它们是最大的小于或等于lookup_value的值,则采用最后一个的位置。 In this case it matches the last 1 since this is the largest value in lookup_vector that is less than or equal to 2 . 在这种情况下,它与最后一个1匹配,因为这是lookup_vector中小于或等于2最大值。

But for this to do, there is the rule, that the values in lookup_vector must be placed in ascending order. 但这是必须遵守的规则,即lookup_vector中的值必须按升序放置。 And this is the not documented feature with this approach. 这是此方法未记录的功能。 It seams as if the #DIV/0! 好像#DIV/0!一样接缝#DIV/0! errors within lookup_vector does not contradict that rule. lookup_vector中的错误与该规则并不矛盾。 But since the source is not open, we can't be absolutely sure about this. 但是由于源代码未公开,因此我们不能完全确定这一点。 But this approach is used sucessfully so often, that we can be very sure. 但是这种方法经常使用成功,因此我们可以肯定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM