首页 \ 问答 \ Excel - 递归VLookup(Excel - Recursive VLookup)

Excel - 递归VLookup(Excel - Recursive VLookup)

我最近才知道Ctrl + Shift +输入Excel的数组公式,并且目前仍在学习它们。 来我的问题,

SheetA:
Product        Code
S1             19875
S2             19834
S1             13575
S1             35675
S2             47875   



SheetB:
Code           Indent
19875          40  
19834          15
13575          22
35675          25
47875          20

我需要做一个给定产品名称的所有缩进的总和。

例如:我需要S1的总缩进,

  • 在SheetA上查找,获取代码19875
  • 在SheetB上执行vlookup,获取40的缩进
  • 在表A上的下一个Vlookup,获取代码13575
  • 在SheetB上使用13575进行Vlookup,获取22的缩进
  • 在表A上的下一个Vlookup,获取代码35675
  • 在SheetB上使用35675进行Vlookup,得到25的缩进
  • 总和40 + 22 + 25,回归87

我可以通过VBA实现这一目标,但是我想知道在使用CSE / Array公式的Excel函数中这是否可行。

编辑:

我在Sheet1中没有与Sheet1相同的顺序值。它们完全是随机的。 我的SheetB会随机的像下面这样:

SheetB:
Code           Indent
19834          40  
19875          15
47875          22
13575          25
35675          20

I recently came to know about Ctrl+Shift+Enter array formulas of Excel and currently still learning them. Coming to my problem,

SheetA:
Product        Code
S1             19875
S2             19834
S1             13575
S1             35675
S2             47875   



SheetB:
Code           Indent
19875          40  
19834          15
13575          22
35675          25
47875          20

I need to do Sum of all Indents of a given Product name.

Eg: I need S1's Total Indent,

  • Vlookup on SheetA, Get the Code 19875
  • Perform a vlookup on SheetB, Get the Indent of 40
  • Next Vlookup on Sheet A, Get the code 13575
  • Use 13575 to Vlookup on SheetB, Get Indent of 22
  • Next Vlookup on Sheet A, Get the code 35675
  • Use 35675 to Vlookup on SheetB, get indent of 25
  • Sum of 40+22+25, Return 87

I can achieve this through VBA, but I'm wondering if this is possible within excel functions using CSE/Array formulas.

Edit:

I don't have values in Sheet2 in the same order of Sheet1.. They are completely random. My SheetB will be something randomly like following:

SheetB:
Code           Indent
19834          40  
19875          15
47875          22
13575          25
35675          20

原文:https://stackoverflow.com/questions/5496952
更新时间:2023-10-03 14:10

最满意答案

您可能想要替换:

 (==) (Add e3 (Add e1 e2)) (Add (Add e4 e5) e6) = (Add(Add e1 e2) e3)==(Add e1 (Add e2 e3)) 

通过

(==) (Add e1 (Add e2 e3)) e = (Add(Add e1 e2) e3) == e
(==) e (Add e1 (Add e2 e3)) = e == (Add(Add e1 e2) e3)

每个方程只是重新平衡一个表达式树以获得左递归,而不试图检查表达式是否实际上是等于,因此您需要第三个等式:

   (==) (Add e1 e2 ) (Add e3 e4) = (e1 == e3) && (e2 == e4)

然后我定义了一个函数,它明确地将Expr作为参数进行测试(==)

testexpr :: Expr -> Expr -> Bool
testexpr a b = a == b

testexpr (1 + (2 +3)) ((1 + 2) + 3)得到True

由于它是一项任务,将代码中的更改集成在一起,并重新组织它以使其工作,这仍然是一项练习。


You might want to replace:

 (==) (Add e3 (Add e1 e2)) (Add (Add e4 e5) e6) = (Add(Add e1 e2) e3)==(Add e1 (Add e2 e3)) 

by

(==) (Add e1 (Add e2 e3)) e = (Add(Add e1 e2) e3) == e
(==) e (Add e1 (Add e2 e3)) = e == (Add(Add e1 e2) e3)

Each equation simply rebalances one expression tree to obtain a left recursion, without trying to check if the expressions are actually equals, so you need a third equation:

   (==) (Add e1 e2 ) (Add e3 e4) = (e1 == e3) && (e2 == e4)

Then I define a function which explicitely takes Expr as parameters to test (==):

testexpr :: Expr -> Expr -> Bool
testexpr a b = a == b

and testexpr (1 + (2 +3)) ((1 + 2) + 3) yields True.

Since it is an assignment, integrating that change in your code, and reorganizing it to make it work is left as an exercise.

相关问答

更多
  • 对于运算符,关联性意味着当相同的运算符出现在一行中时,那么我们先运行哪个运算符。 在下面,让Q为运算符 a Q b Q c 如果Q是关联的,那么它评估为 (a Q b) Q c 如果它是正确的关联,那么它评估为 a Q (b Q c) 这很重要,因为它改变了表达式的含义。 考虑具有整数算术的除法运算符,它是左关联的 4 / 2 / 3 <=> (4 / 2) / 3 <=> 2 / 3 = 0 如果它是正确的关联,它会评估一个未定义的表达式,因为你将除以零 4 / 2 / ...
  • 1 in [] in 'a'被评估为(1 in []) and ([] in 'a') 。 由于第一个条件( 1 in [] )为False ,因此将整个条件评估为False ; ([] in 'a')从未被实际评估,因此不会引起错误。 以下是语句定义: In [121]: def func(): .....: return 1 in [] in 'a' .....: In [122]: dis.dis(func) 2 0 LOAD_CONST ...
  • 据我所知,这是一个无法从软件重新配置的硬件设计参数。 通常,这种事情使用硬件模拟器进行优化。 已经对软件可配置缓存进行了研究,但我还没有听说过将它变成流行的通用处理器。 - 或者我的建筑知识已经过时了...... To the best of my knowledge this is a hardware design parameter that can't be reconfigured from software. Typically, this kind of thing is optimized ...
  • 看看这个漂亮的插图 。 以下是它的工作原理:您的地址大小为16位,因此标记的16位加上索引加上缓存块中的偏移量。 如果我们假设我们想要在缓存中寻址单个字节(通常是这种情况),我们需要3个位来寻址块内的1个字节(因为每个缓存块都是8 = 2 ^ 3个字节)。 这为索引留下了16 - 3 - 11 = 2个字节。 用两个字节,我们可以解决2 ^ 2 = 4个不同的集合。 我们在缓存中有256/8 = 32个块(缓存的大小/一个块的大小)。 这32个块被分成4组,因此每组包含8个缓存块。 您的缓存因此是8路关联。 ...
  • JavaScript从左到右评估表达式。 我们可以通过使用其他变量来显示正在发生的事情: var foo = {}; var bar = foo; // keep a reference to the object originally stored in foo foo.x = foo = {n: 2}; 由于关联性,最后一个语句被解析为: foo.x = (foo = {n: 2}); 但是由于评估顺序, foo.x首先运行(确定存储值的位置),然后是foo ,然后运行{n: 2} 。 所以我们将 ...
  • 我不敢相信有这么多错误(删除)的答案......也许我应该回答这个问题。 首先, 优先!=关联!=评估顺序 。 现在我们已经解决了这个问题:在某些情况下,关联性很重要。 对于a + b + c ,当a , b和c是浮点数而不是整数时,这很重要,因为舍入误差将根据术语的分组方式而不同地累积。 对于&&和||的特殊情况 , 只要它们没有被重载 (这只能在C ++中,而不是在C中),那么它并不重要,但是为了一致性,语言仍然定义了一个 - 并且使得代码的“树”表示(基于在语法上)是独一无二的。 从现在开始,C ++ ...
  • 通常它的语法是“自然的”: 考虑x - y + z 。 你希望它是从左到右,以便得到(x - y) + z而不是x - (y + z) 。 考虑a = b = c 。 你希望这是从右到左,以便得到a = (b = c) ,而不是(a = b) = c 。 我无法想象这个选择似乎是“任意”做出的例子。 免责声明:我不知道Ruby,所以我上面的示例基于C语法。 但我相信Ruby中也适用相同的原则。 Typically it's so the syntax is "natural": Consider x - y ...
  • 您可能想要替换: (==) (Add e3 (Add e1 e2)) (Add (Add e4 e5) e6) = (Add(Add e1 e2) e3)==(Add e1 (Add e2 e3)) 通过 (==) (Add e1 (Add e2 e3)) e = (Add(Add e1 e2) e3) == e (==) e (Add e1 (Add e2 e3)) = e == (Add(Add e1 e2) e3) 每个方程只是重新平衡一个表达式树以获得左递归,而不试图检查表达式是否实际上是等 ...
  • Formula的Show实例可能如下所示: instance Show Formula where showsPrec _ (Atom name) = showString name showsPrec p (Not formula) = showParen (p > 3) $ showString "\\+ " . showsPrec 3 formula showsPrec p (And lhs rhs) = showParen (p > 2) $ showsPrec 3 lh ...
  • 您的优先 顺序与执行顺序混淆。 例: a[b] += b += c * d + e * f * g 优先规则规定*来自+之前+=之前。 关联性规则(它是优先规则的一部分)表明*是左关联的, +=是右关联的。 优先级/关联性规则基本上定义了隐式括号的应用,将上述表达式转换为: a[b] += ( b += ( (c * d) + ((e * f) * g) ) ) 但是,此表达式仍然是从左到右评估的 。 这意味着表达式a[b]中b的索引值将使用b执行b += ...之前的b += ...值。 有关更复杂的 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。