DSUM 公式不起作用

DSUM Formula Not Working

我的数据库查询中有一个 DSUM 公式,它使用以下公式计算出发票上要支付的剩余未付金额。

它在大多数情况下工作正常,但是在有尚未付款的发票的情况下它不起作用,在这种情况下没有付款可参考并且公式产生“#Error”在公式单元格中。

请问我如何更改以下内容以使其适用于没有付款的发票?

非常感谢

付款前未结金额:IIf([发票金额]=0,0,IIf([发票金额]-Nz(DSum([已付金额]","Payments Table Combined with Invoice Table", "[Invoice Number] = " & [Invoice Number] & " And [Payment Date] < " & Format([Payment Date],"#yyyy-mm-dd#")),0)=0,0,[Invoice Amount]-Nz(DSum([Amount Paid],"Payments Table Combined with Invoice Table",[Invoice Number] = " & [Invoice Number] & " And [Payment Date] < " & Format([Payment Date]," #yyyy-mm-dd#")),0)))

您可以减少它并使用 Nz 作为空的付款日期:

Amount Outstanding Before Payment: IIf([Invoice Amount]=0,0,[Invoice Amount]-Nz(DSum("[Amount Paid]","Payments Table Combined with Invoice Table","[Invoice Number] = " & [Invoice Number] & " And Nz([Payment Date],Date()) < " & Format(Nz([Payment Date],Date()),"\#yyyy-mm-dd\#") & ""),0))