简体   繁体   English

SSRS Tablix显示销售与预算

[英]SSRS tablix show sales vs budget

I am struggling to understand a way to get the following in a proper tablix in SSRS. 我正在努力了解一种在SSRS的适当列表中获得以下内容的方法。

I would like to have a tablix report with the following. 我想要一份带有以下内容的tablix报告。

           NOV 2016         DEC 2016 
           Sales Target     Sales Target 
CustomerA   100   200        400    300

My datasets are all in SQL Server 2008 R2 我的数据集都在SQL Server 2008 R2中

dataset1 to get the sales numbers. dataset1以获取销售数量。

Customer  InvoiceDate Salesvalue
CustomerA 05/11/2016  50
CustomerA 04/11/2016  50
etc

dataset2 has the targets. dataset2具有目标。

   Customer   date      Target
   CustomerA  11/2016   200
   CustomerA  12/2016   300

I just cannot manage to "merge" these 2 tables together and get my target next to the sales for each month. 我只是无法设法将这两个表“合并”在一起并将我的目标放在每个月的销售额旁边。

I managed to get it done in powerBI as there you can nicely add a relationship between the tables based on an extra DimTimTable where I link the date with the invoice date and the add a filter just based on month. 我设法在powerBI中完成它,因为您可以在其中基于额外的DimTimTable添加表之间的关系,在该表中,我将日期与发票日期链接在一起,并仅基于月份添加过滤器。

I am just wondering how my datasets should look to get sales (which is based on the invoicedates) next to the budgets which are linked to the month. 我只是想知道我的数据集应该如何获得与月链接的预算旁边的销售额(基于发票)。

So I am struggling to understand how to model this and if SSRS and SQLserver is correct for this? 因此,我正在努力了解如何对此建模,以及SSRS和SQLserver是否对此正确? Should I create a "cube" for this before I can achieve this? 我应该为此创建一个“多维数据集”吗?

You can do this in SQL. 您可以在SQL中执行此操作。

First Sum your sales by customer and month, note I have used the datediff/dateadd, to find the first day of the month 首先按客户和月份对您的销售额求和,请注意,我已经使用datediff / dateadd来查找月份的第一天

SELECT Customer, DATEADD(month, DATEDIFF(month, 0, InvoiceDate, 0) as StartMonth, Sum(Salesvalue) as Sales
FROM dataset1
GROUP BY Customer, DATEADD(month, DATEDIFF(month, 0, InvoiceDate, 0)

Convert your Forecast tables date field so it is consistent and also has the first day of the month 转换您的“预测表”日期字段,使其保持一致,并具有每月的第一天

SELECT Customer, CONVERT(date, '01/' + date , 103) as StartMonth, Target
FROM dataset2

You can also join in a calendar file if you don't want gaps in your data and join that with a list of your customers, that way you will get all possible values in your pivot. 如果您不希望数据之间存在空白,也可以加入日历文件,并与客户列表一起加入日历文件,这样一来,您就可以获取所有可能的值。 But for simplicity I will just do an outer join between the two, since you are likely to have either a sale or a target for each desired month in your range. 但为简单起见,我将仅在两者之间进行外部连接,因为您很可能在范围内的每个所需月份都有销售或目标。

SELECT ISNULL(Sales.Customer, Targets.Customer) as Customer, 
 ISNULL(Sales.StartMonth, Targets.StartMonth) as StartMonth,
 Sales, 
 Target
FROM (SELECT Customer, DATEADD(month, DATEDIFF(month, 0, InvoiceDate, 0) as     StartMonth, Sum(Salesvalue)  Sales 
FROM dataset1
GROUP BY Customer, DATEADD(month, DATEDIFF(month, 0, InvoiceDate, 0)) as ConvertedSales 
OUTER JOIN
(SELECT Customer, CONVERT(date, '01/' + date , 103) as StartMonth, Target
  FROM dataset2) Targets
 ON Sales.Customer = Targets.Customer AND Sales.StartMonth = Target.SalesMonth

Now you can create your pivot using this dataset 现在,您可以使用此数据集创建数据透视

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM