Unexpected error: Operation is not valid due to the current state of the object

Unexpected error: Operation is not valid due to the current state of the object

我在 power query[Excel] 的文本列上尝试 运行 此函数时出现上述错误。 该列包含不同的名称,此函数检查条目中是否包含“AbbVie”、“Roche”或“Pfizer”。它 returns 条目中存在的列表中的名称。

    (txt as text) =>
[
   
   create_val = (val as text,check as text, output as text) =>
     let 
       output = if Text.Contains(val,check)
       then Text.Combine({output, check},",")
       else output
     in
       output,
    final_value = List.Accumulate({"AbbVie","Roche","Pfizer"},"",(state,current) => create_val(txt,current,state))
][final_value]

我也遇到了这个问题,所以我想分享一下我是如何解决它的。

我递归地使用自定义函数,作为实现循环的一种方式。事实证明我是在修改函数定义中的变量,即调用函数时使用的变量。通过声明局部变量,该函数按预期工作。