0

我有一个数据集,一个 sql 查询的输出,它给了我以下输出:

Year Month  TotalSales  TotalProducts
2013   1          23233           45
2013   2           3344           43
2013   3             232             11
2013   4            2232           23

我正在尝试使用 SSRS 在表格和条形图中表示上述数据集。

有没有办法可以将几个月限制在 SSRS 的最后三个月?

我在 SSRS 中使用当前月份作为参数。

例如:我选择第 4 个月作为参数,我想在条形图和表格中仅查看第 4,3 和 2 个月的结果

有什么办法可以做到吗?

实际查询如下所示:

SELECT ISNULL(x.[Month],z.[Month]) AS [Month],  
       ISNULL(x.Sum_Stores, 0) - ISNULL(y.Sum_SalesStores, 0) AS Difference , ISNULL(Sum_onetonine, 0) as EcontractsbetweenOneandNine........................
FROM   
(
    SELECT [Month], Sum(Stores) AS Sum_Stores 
    FROM   SUM_XXX 
    WHERE  [Year] = '2013' and Name = 'Pro'
    GROUP BY [Month]
) AS x
FULL OUTER JOIN
(
    SELECT [Month], Sum(tracts) AS Sum_SalesStores 
    FROM   SUM_yyy 
    WHERE  [Year] = '2013' and Name = 'Pro'
    GROUP BY [Month]
) AS y ON x.[Month] = y.[Month] 
............................
4

2 回答 2

0

在 SSRS 中有几种方法可以实现这一点。

如果是的话,是否要限制查询返回的结果使用查询参数链接

或者您可以将过滤器应用于数据集/数据区域链接

你基本上想要做的是(伪)

DataSet!Month.Value BETWEEN Parameter!Month.Value-2 AND Parameter!Month.Value

这没有正确考虑第 1 个月和第 2 个月。当我有更好的解决方案而不是复杂的if-else.

编辑:如果您将一个MonthStart字段添加到结果集中作为正确的DATETIME并用作MonthStart参数的值,那么您可以这样做

DataSet!Month.Value BETWEEN DATEADD (MONTH, -2, Parameter!Month.Value) AND Parameter!Month.Value
于 2013-11-12T23:32:06.580 回答
0
declare @ParamDate DateTime =null; -- Pass the required date in datetime format
                                   -- as per your example pass @ParamDate as '20130401'
SET @ParamDate = getdate(); --setting the current date for demo purpose

SELECT ISNULL(x.[Month],z.[Month]) AS [Month],  
       ISNULL(x.Sum_Stores, 0) - ISNULL(y.Sum_SalesStores, 0) AS Difference , ISNULL(Sum_onetonine, 0) as EcontractsbetweenOneandNine........................
FROM   
(
    SELECT [Month], Sum(Stores) AS Sum_Stores 
    FROM   SUM_XXX 
    WHERE  ([Year] = year(@ParamDate) or [Year] = year(dateadd(m,-2,@ParamDate)) )
            and ([Month] = month(@ParamDate) or [Month] = month(dateadd(m,-2,@ParamDate)) )
            and Name = 'Pro'
    GROUP BY [Month]
) AS x
FULL OUTER JOIN
(
    SELECT [Month], Sum(tracts) AS Sum_SalesStores 
    FROM   SUM_yyy 
    WHERE  ([Year] = year(@ParamDate) or [Year] = year(dateadd(m,-2,@ParamDate)) )
            and ([Month] = month(@ParamDate) or [Month] = month(dateadd(m,-2,@ParamDate)) )
            and Name = 'Pro'
    GROUP BY [Month]
) AS y ON x.[Month] = y.[Month] 
............................
于 2013-11-13T01:18:01.517 回答