【问题标题】:Adding Tolerances to Excel LAMBDA functions向 Excel LAMBDA 函数添加公差
【发布时间】:2022-09-23 18:30:26
【问题描述】:

我创建了一个名为 LOANAMT 的 LAMBDA 函数,用于递归计算贷款金额,以应对您需要借钱来支付贷款的情况(是的,我知道这可以通过代数方式解决——我正在尝试了解 LAMBDA)。 我将容差检查作为我的免责条款;如果下一轮利息计算与上一轮非常接近,则 LAMBDA 退出。这适用于硬编码的容差水平 0.001:

=LAMBDA(opening_balance, base_rate, [interest],
    LET(
        _int, IF(ISOMITTED(interest), 0, interest),
        _new_close, opening_balance + _int,
        _new_int, _new_close * base_rate,
        _closing_balance, IF(ABS(_new_int-_int)<0.001, _new_close,LOANAMT(opening_balance,base_rate,_new_int)),
        _closing_balance
    )
)

给我 106.38290,其中 opening_balance = 100,base_rate = 6%,与代数解大致一致。

但是,当我尝试将容差作为 LAMBDA 的一个参数以便可以轻松调整时,我得到了 #NUM 错误。

=LAMBDA(opening_balance, base_rate, tolerance, [interest],
    LET(
        _int, IF(ISOMITTED(interest), 0, interest),
        _new_close, opening_balance + _int,
        _new_int, _new_close * base_rate,
        _closing_balance, IF(ABS(_new_int-_int)<tolerance, _new_close,LOANAMT2(opening_balance,base_rate,_new_int)),
        _closing_balance
    )
)

谁能解释发生了什么问题并帮我解决这个问题? 谢谢。

    标签: excel-formula excel-lambda


    【解决方案1】:

    第二个版本没有将公差值传递给对 LOANAMT2 的递归调用,因此是 #NUM!错误。

    这有效:

    LOANAMT2=LAMBDA(opening_balance, base_rate, tolerance, [interest],
        LET(
            _int, IF(ISOMITTED(interest), 0, interest),
            _new_close, opening_balance + _int,
            _new_int, _new_close * base_rate,
            _closing_balance, IF(ABS(_new_int-_int)<tolerance, _new_close,LOANAMT2(opening_balance,base_rate,tolerance,_new_int)),
            _closing_balance
        )
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-28
      • 2021-10-09
      • 2015-05-21
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多