如何在SSRS中使用datediff进行求和

时间:2013-04-11 23:21:44

标签: reporting-services sum expression datediff

我的目标是从Visual Studio 2008中的SSRS表达式中获取* .rdl报告中的以下结果.DuedDate和InvoiceAmt是绑定字段(字段!duedate.Value和fields!valuehome_1)。 “NotDueYet”和“0-30 Days”是具有引用绑定字段的表达式的别名。

ClientInvoice>>> DueDate>>> InvoiceAmt>>>> NotDueYet>>>> 0-30天
4502767-00>>>→4/8/2013年>>>> $ 75.89>>>>>>>>>>>>>&GT ;>>>>>> $ 75.89

4505151-00>>>→4 /二千零十三分之十一>>> $ 137.26>>>>>>> $ 137.26

>>>>>>>>>>>>>>>>>>>的 $ 213.15 >>>>>>>的 $ 137.26 >>>>>>的 $ 75.89

问题: 在Alias列“NotDueYet”和“0-30 Days”中,根据下面支持总计的iif / sum / datediff表达式,总计应该是仅显示在这些列中的详细数量(参见上面的示例)。详细信息量基于引用Duedate和InvoiceAmt绑定字段的表达式。相反,我得到以下结果;

ClientInvoice>>> DueDate>>> InvoiceAmt>>>> NotDueYet>>>> 0-30天
4502767-00>>>→4/8/2013年>>>> $ 75.89>>>>>>>>>>>>>&GT ;>>>>>> $ 75.89

4505151-00>>>→4 /二千零十三分之十一>>> $ 137.26>>>>>>> $ 137.26

>>>>>>>>>>>>>>>>>>>的 $ 213.15 >>>>>?>>的 $ 0.00 >>>>>>>>的 $ 213.15

以下是每个字段的表达式;

InvoiceAmt(DETAIL):

=(fields!valuehome_1.Value)

InvoiceAmt(TOTAL):

=Sum(fields!valuehome_1.Value)

NotDueYet(DETAIL):

= iif(datediff("d",fields!duedate.Value,now())<= 0 
and (fields!valuehome_1.value>0),fields!valuehome_1.Value,"")

NotDueYet(TOTAL):

= iif(datediff("d",fields!duedate.Value,now())<= 0 
and (fields!valuehome_1.value>0),SUM(fields!valuehome_1.Value),0)

0-30天(细节):

= iif(datediff("d",fields!duedate.Value,now())>0 
and (datediff("d",fields!duedate.Value,now())<31 
and (fields!valuehome_1.value>0),fields!valuehome_1.Value,"")

0-30天(TOTAL):

= iif(datediff("d",fields!duedate.Value,now())>0 
and (datediff("d",fields!duedate.Value,now())<31 
and (fields!valuehome_1.value>0),SUM(fields!valuehome_1.Value),0)

我感谢任何协助解决这个谜团。谢谢。

1 个答案:

答案 0 :(得分:0)

嵌套不太正确:尝试以下表达式:

对于NotDueYet(TOTAL):

=SUM(
    iif(datediff("d",fields!duedate.Value,now())<= 0
        and (fields!valuehome_1.value>0),
      fields!valuehome_1.Value,
      0))

0-30天(TOTAL):

= SUM(
   iif(datediff("d",fields!duedate.Value,now())>0
       and (datediff("d",fields!duedate.Value,now())<31 
       and (fields!valuehome_1.value>0),
      fields!valuehome_1.Value,
      0))

我认为应该得到你想要的东西。