在SSRS报告中创建一个列,以根据前一列的条件对值进行求和

时间:2017-12-20 17:39:34

标签: sql-server reporting-services ssrs-2012

我有一份ssrs报告,根据用户输入的开始和结束日期参数显示了一年中每个月的收入。我想要做的是添加第二列,显示该季度的收入(3月将显示q1收入,6月q2等)。我遇到的问题是,我能够在一年内完成这项任务,但一旦查询开始查看多年,我的专栏就会显示所有第一季度的价值,无论年份如何。图为我目前得到的内容。关于如何修正我的表达式的任何建议,也可以在总结这些季度时查看年份值?

以下是我用来仅根据月份填充季度列的代码。

    =IIF(Fields!Sort_Order.Value=3,
        Sum(Lookup(1,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(2,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(3,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),
    IIF(Fields!Sort_Order.Value=6,
Sum(Lookup(4,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(5,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(6,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),
    IIF(Fields!Sort_Order.Value=9,
    Sum(Lookup(7,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(8,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(9,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),
    IIF(Fields!Sort_Order.Value=12,
    Sum(Lookup(10,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(11,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings"))
    +Sum(Lookup(12,Fields!Sort_Order.Value,Fields!Calculated_Revenue.Value,"Bookings")),""))))

enter image description here

1 个答案:

答案 0 :(得分:0)

我最终在我的数据集中创建了一个四分之一列,然后将其用作月份行的父组。然后,我隐藏了那个专栏,并在该季度添加了总计,这给了我小计。不完全是我想要的,但给了我需要的结果。enter image description here