简体   繁体   English

如何使 lambda function 在 excel365 上工作?

[英]How to make lambda function working on excel365?

I'm using excel 365,我正在使用 excel 365,

Can someone please explain why this function is not working as expected?有人可以解释为什么这个 function 没有按预期工作吗? I don't know what is the reason behind?不知道背后的原因是什么?

在此处输入图像描述

Below is a screenshot of an excel simulation in Google Sheets, which produces the expected result:下面是 Google 表格中 excel 模拟的屏幕截图,它产生了预期的结果:

在此处输入图像描述

It seems to be a bug in BYROW function, because replacing it with MAP works.它似乎是BYROW function 中的一个错误,因为用MAP替换它是有效的。

=MAP(SEQUENCE(5), LAMBDA(b, TEXTJOIN(",",, SEQUENCE(5,,b))))

excel输出

By the way this is not the first time that I have seen an unexpected behavior with BYROW that MAP doesn't have it.顺便说一句,这不是我第一次看到MAP没有BYROW的意外行为。 It seems to be more robust.它似乎更坚固。 When LAMBDA for MAP has a single name both functions are equivalent .LAMBDAMAP有一个名字时,两个函数是等价的。

It is curious, Google Spreadsheet that emulates Excel functions, doesn't have this odd behavior.奇怪的是,模拟 Excel 函数的 Google 电子表格没有这种奇怪的行为。 It works, but you need to enter the third input argument ( start ) of SEQUENCE otherwise it returns #NUM!它可以工作,但是您需要输入SEQUENCE的第三个输入参数 ( start ),否则它会返回#NUM! , because the default value is 0 and not 1 . ,因为默认值为0而不是1

G表输出

Not an answer to the actual question (why BYROW behaves unpredictable in given example), but an alternate solution to get the desired result:不是对实际问题的回答(为什么 BYROW 在给定示例中的行为不可预测),而是获得所需结果的替代解决方案:

BYROW is limited in 1D spills only and therefore if we want a 2D spill result we need to use REDUCE. BYROW 仅限于 1D 溢出,因此如果我们想要 2D 溢出结果,我们需要使用 REDUCE。

If you work with REDUCE you could spill the result you like:如果你使用 REDUCE,你可能会溢出你喜欢的结果:

=DROP(REDUCE(0,SEQUENCE(5),LAMBDA(x,y,VSTACK(x,TEXTJOIN(",",,SEQUENCE(5,,y))))),1)

在此处输入图像描述

You need to declare a start and an array to "loop" through.您需要声明一个开始和一个数组以“循环”通过。 x and y in this example.本例中的xy It starts at x , then does it's first calculation using y and the result becomes the next x.它从x开始,然后使用y进行第一次计算,结果成为下一个 x。 Using VSTACK makes that visible, otherwise it would do it's calculations until the final y value is used and shows that only.使用 VSTACK 使其可见,否则它会进行计算,直到使用最终的y值并仅显示该值。 Stacking them makes each calculation visible and unlike BYROW it can spill 2D.堆叠它们使每个计算都可见,并且与 BYROW 不同,它可以溢出 2D。 Since you started x at 0 without any calculations yet, the first value needs to drop using DROP.由于您在没有任何计算的情况下从0开始x ,因此需要使用 DROP 删除第一个值。 The end result is a 2D spill of what you want.最终结果是您想要的二维溢出。

(Could also be used with horizontal arrays and HSTACK.) (也可以与水平 arrays 和 HSTACK 一起使用。)

You could also spill down and sideways (without TEXTJOIN): =DROP(REDUCE(0,SEQUENCE(5),LAMBDA(x,y,VSTACK(x,SEQUENCE(1,5,y)))),1)你也可以向下和向侧面溢出(没有 TEXTJOIN): =DROP(REDUCE(0,SEQUENCE(5),LAMBDA(x,y,VSTACK(x,SEQUENCE(1,5,y)))),1) 在此处输入图像描述

=MAP(SEQUENCE(5),LAMBDA(x,TEXTJOIN(",",1,SEQUENCE(1,5,x)))) Also bypasses the BYROW unexpected result. =MAP(SEQUENCE(5),LAMBDA(x,TEXTJOIN(",",1,SEQUENCE(1,5,x))))也绕过 BYROW 意外结果。

This works well in GSheet (my Excel is 2019)这在 GSheet 中运行良好(我的 Excel 是 2019)

=BYROW(SEQUENCE(5),LAMBDA(b,TEXTJOIN(",",,SEQUENCE(1,5,b))))

The seconde sequence is changed from empty to 1.第二个序列从空变为 1。

Problem: It seems that the BYROW function is not performing as expected in this formula:问题:在这个公式中, BYROW function似乎没有按预期执行:

= BYROW( SEQUENCE( 5 ), LAMBDA(Sqn, TEXTJOIN( ",", , SEQUENCE( 5, , Sqn ) ) ) )

As noted in the comments if the array parameter SEQUENCE(5) is replaced by a range (eg, $B$3# as in the picture below) the formula returns the expected result.如注释中所述,如果array参数SEQUENCE(5)被一个范围替换(例如,下图中的$B$3# ),则公式将返回预期结果。
在此处输入图像描述

Now if the range $B$3# is the result of the array parameter in the original formula, why the original formula “does not show" the expected result?.现在,如果$B$3#范围是原始公式中array参数的结果,为什么原始公式“没有显示”预期结果?。
在此处输入图像描述

Let's enter the problem formula in cell [F10] , then press F2 to edit, then press F9 to calculate the result of the formula, …让我们在单元格[F10]中输入问题公式,然后按F2进行编辑,然后按F9计算公式的结果,...
在此处输入图像描述

then press enter , and we'll see the expected result in the range [F10:F14] .然后按enter ,我们将在[F10:F14]范围内看到预期的结果。
在此处输入图像描述

Well, it seems that the formula is working as expected, however, it’s “not showing” the correct result.好吧,公式似乎按预期工作,但是,它“没有显示”正确的结果。 This behavior is due to Excel's upgraded formula language.此行为是由于 Excel 的升级公式语言。

Before the implementation of dynamic arrays, the default calculation was “Implicit Intersection” (ie, reduce many values to a single value), as such, there was the need to wrap the legacy array formulas with braces {} to show multiple values.在实现动态arrays之前,默认计算是“隐式交集”(即,将多个值减少为一个值),因此需要用大括号{}包裹遗留数组公式以显示多个值。 Now, with the dynamic arrays, the default is to “spill” the results (ie, excel will dynamically size the output range\array as required by the multiple values generated).现在,对于动态 arrays,默认是“溢出”结果(即,excel 将根据生成的多个值的需要动态调整 output 范围\数组的大小)。

In this case, the output of the LAMBDA function has many values, therefore the result is “spilled” , however, we need to combine them into one single value, and for this purpose, we use the Implicit intersection operator: @ .在这种情况下,LAMBDA function 的 output 有很多值,因此结果是“溢出” ,但是,我们需要将它们组合成一个值,为此,我们使用隐式交集运算符:@

The formula shall become:公式应变为:

= BYROW( SEQUENCE( 5 ), LAMBDA(Sqn, TEXTJOIN( ",", , SEQUENCE( 5, , @Sqn ) ) ) )

Now let's enter the formula above in cell [D18] .现在让我们在单元格[D18]中输入上面的公式。
Excel will propose a variation of the formula that applies "implicit intersection” to the entire formula, ie, Excel 将提出对整个公式应用“隐式交集”的公式变体,即,

= @BYROW( SEQUENCE( 5 ), LAMBDA(Sqn, TEXTJOIN( ",", , SEQUENCE( 5, ,@Sqn ) ) ) ) = @BYROW( 序列( 5 ), LAMBDA(Sqn, TEXTJOIN( ",", , 序列( 5, ,@Sqn ) ) ) )
在此处输入图像描述

Reject the proposed formula, because we need a mixed formula that relies on both array calculation and implicit intersection.拒绝提议的公式,因为我们需要一个既依赖数组计算又依赖隐式交集的混合公式
Now we have the expected result in range [F18:F22]现在我们在[F18:F22]范围内得到了预期的结果
在此处输入图像描述

Note that the second SEQUENCE, could either be: SEQUENCE( 5, ,@Sqn ) or SEQUENCE( 1, 5,@Sqn ) , both return the same result as they will be joined by the TEXTJOIN function.请注意,第二个 SEQUENCE 可以是: SEQUENCE( 5, ,@Sqn )SEQUENCE( 1, 5,@Sqn ) ,两者都返回相同的结果,因为它们将由TEXTJOIN function 连接。
在此处输入图像描述

For additional information please see:有关其他信息,请参阅:
Implicit intersection operator: @ 隐式交集运算符:@
Dynamic array formulas and spilled array behavior 动态数组公式和溢出数组行为

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

相关问题 Excel365“序列”与“如果”相结合 - Excel365 'Sequence' combined with 'If' 当我打开excel365时出现错误 - Error in excel365 when I turn it on 如何在 excel365 vba 项目窗口中更改字体大小? - How can I change the fontsize in excel365 vba Project Window? excel365 - 根据两个字符串值有条件地格式化行? - excel365 - Conditionally format rows based on two string values? Excel365 VBA 在 Mac 上编译错误以生成 Outlook 事件 - “无法找到项目或库” - Excel365 VBA Compile Error on Mac for Generating Outlook Events - 'A Project or Library Cannot be Found' #价值! 在 Excel 中使用 Lambda 和 ByRow Helper Function 时出错 (365) - #VALUE! Error Using Lambda And ByRow Helper Function in Excel (365) 如何制作一个 excel (365) function 识别同一单元格中的不同单词并单独更改它们 - How to make an excel (365) function that recognizes different words in the same cell and changes them individually Excel 365功能参数中的“此功能帮助”链接不起作用 - “Help on this function” link in Excel 365 Function Argument not working Erl() function 不能在 64 位中工作 O365 Excel VBA - Erl() function not working in 64 bit O365 Excel VBA Excel 365 个函数/公式名称被翻译。 如何避免? - Excel 365 function/formula names gets translated. How to avoid it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM