Microsoft Access Expression - DSum Multiple Criteria - 日期

时间:2016-11-22 23:30:00

标签: vba ms-access expression

我正在尝试使用多个条件编写DSum表达式,但似乎无法正确使用它。不完全是Access-savvy,但很确定我的语法正确。我只用一个标准得到的结果是正确的。当我添加第二个时,表达式忽略两个条件,并为我提供整个列的总和。知道我做错了什么???目标是为每个广告系列设置“滚动总计”,因此每次发送新发票时,都会将其添加到此滚动总计字段中。最佳excel等效公式:=SUMIFS(current_invoice_amount,campaign_id,A2,invoice_date,"<="&B2) A2 is campaign id and B2 is invoice date. Pretend formula is in C2.

以下是无效的Access表达式:

Expr1: DSum("[current_invoice_amount]","[tblAccountingDatabase]","[campaign_id]='" & [campaign_id] & "'" And "[invoice_date]<=#" & [invoice_date] & "#")

以下是表格的样子:

campaign   invoice_date   current_invoice_amount   rolling_total
a             1/1/16                5                    5
a             2/1/16                6                    11
a             3/1/16                4                    15
b             1/1/16                4                    4
b             2/1/16                4                    8
c             1/1/16                6                    6

1 个答案:

答案 0 :(得分:0)

如果[campaign_id]字段是数字类型,请勿将其放在单引号中。

如果[invoice_date]字段是日期类型,请不要将其括在#tags中。

Expr1: DSum("[current_invoice_amount]","[tblAccountingDatabase]","[campaign_id]=" & [campaign_id] & " And [invoice_date]<=" & [invoice_date])