答案 0 :(得分:0)
我不确定这是否是最好的方法,但是为了获取图表数据,我会取消您的数据并在数据集中创建两列。下面是一些示例代码,可以将您演示的数据集转换为更易于图表处理的内容。
-- CREATE A Month NUmber table
-- Create this as a physical table, I'm doing this as a Table variable for this exmaple only
-- CREATE TABLE dbo.Months (Month_Name varchar(3), Month_Number int)
DECLARE @Month TABLE(Month_Name varchar(3), Month_Number int)
INSERT INTO @Month VALUES
('Jan', 1), ('Feb', 2), ('Mar', 3), ('Apr', 4), ('May', 5), ('Jun', 6),
('Jul', 7), ('Aug', 8), ('Sep', 9), ('Oct', 10), ('Nov', 11), ('Dec', 12)
-- CREATE and populate dummy table
DECLARE @t table (FranchiseNumber int, Report_Year int, Jan int, Feb int, Mar int, Apr int, May int, Jun int, Jul int, Aug int, Sep int, Oct int, Nov int, Dec int)
INSERT INTO @t Values
(103332, 2016, 578,591,616,611,611,577, NULL, NULL, NULL, NULL, NULL, NULL),
(103332, 2017, 343,332,324,310,309, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
DECLARE @d TABLE(FranchiseNumber int, Month_Name varchar(3), Previous_Year int, Current_Year int)
-- unpivot, create prev and current year columns and add a month number to help sort the Axis
INSERT INTO @d
select
FranchiseNumber
, Month_Name
--, DATEPART(MM, Month_Name + ' 01 1999') AS Month_Number -- REMOVED
, SUM(CASE Report_Year WHEN 2016 THEN Month_Value ELSE NULL END) AS Previous_Year
, SUM(CASE Report_Year WHEN 2017 THEN Month_Value ELSE NULL END) AS Current_Year
from
@t p
UNPIVOT
(Month_Value FOR
Month_Name IN (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
) as unPiv
GROUP BY FranchiseNumber, Month_Name, DATEPART(MM, Month_Name + ' 01 1999')
SELECT d.FranchiseNumber, m.Month_Name, m.Month_Number, d.Previous_Year, d.Current_Year
FROM @Month m
LEFT JOIN @d d ON m.Month_Name = d.Month_Name
图表设计看起来像这样。
我所做的只是创建折线图将当前和上一年的列拖到值区域,单击值区域中的Previous_Year下拉列表并将图表类型更改为列。
之后我右键单击水平轴并按Month_Number
排序更新:您可能需要右键单击水平轴,选择属性并将间隔更改为1,否则可能无法显示所有月份标签。
它并不完美,但它应该让你接近。
要生成下面的表格,请添加一个新数据集,指向原始数据并添加指向它的新Tablix。
希望有所帮助。