SSRS Tablix Cell Calculation based on RowGroup Value

偶尔善良 提交于 2019-12-12 06:16:55

问题


I have looked through several of the posts on SSRS tablix expressions and I can't find the answer to my particular issue.

I have a dashboard I am creating that contains summary data for various managers. They are entering monthly summary data into a single table structured like this:

Create TABLE OperationMetrics
AS
Date date
Plant char(10)
Sales float
ReturnedProduct float

The data could use some grouping so I created a table for referencing which report group these metrics go into looks like this:

Create Table OperationsReport
as
ReportType varchar(50)
MetricType varchar(50)

In this table, 'Sales' and 'ReturnedProduct' are the Metric column, while 'ExecSummary' or 'Quality' are ReportType entries. To do the join, I decided to UNPIVOT the OperationMetrics table...

Select Date, Plant, Metric, MetricType 
From (Select Date, Plant, Sales, ReturnedProduct From OperationMetrics)
UNPVIOT (Metric for MetricType in (Sales, ReturnedProduct) UnPvt

and join it to the OperationsReport table so I have grouped metrics.

Select Date, Plant, Metric, Rpt.MetricReport, MetricType
FROM OpMetrics_Unpivoted OpEx 
INNER JOIN OperationsReport Rpt on OpEx.MetricType = Rpt.MetricType 

(I understand that elements of this is not ideal but sometimes we are not in control of our destiny.)

This does not include the whole of the tables but you get the gist. So, they have a form they fill in the OperationMetrics table. I chose SSRS to display the output.

I created a tablix with the following configuration (I can't post images due to my rep...)

Date is the only column group, grouped on 'MMM-yy' Parent Row Group is the ReportType Child Row Group is the MetricType

Now, my problem is that some of the metrics are calculations of other metrics. For instance, 'Returned Product (% of Sales)' is not entered by the manager because it is assumed we can simply calculate that. It would be ReturnedProduct divided by Sales.

I attempted to calculate this by using a lookup function, as below:

Switch(Fields!FriendlyName.Value="Sales",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProduct",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProductPercent",Lookup("ReturnedProduct",
Fields!FriendlyName.Value,Fields!Metric.Value,"MetricDataSet")/
Lookup("Sales",Fields!FriendlyName.Value,Fields!Metric.Value,
"MetricDataSet"))

This works great! For the first month... but since Lookup looks for the first match, it just posts the same value for the rest of the months after.

I attempted to use this but it got me back to where I was at the beginning since the dataset does not have the value.

Any help with this would be well received. I would like to keep the rowgroup hierarchy.


回答1:


It sounds like the LookUp is working for you but you just need to include the date to find the right month. LookUp will return the first match which is why it's only working on the first month.

What you can try is concatenating the Metric Name and Date fields in the LookUp.

Lookup("Sales" & CSTR(Fields!DATE.Value), Fields!FriendlyName.Value & CSTR(Fields!DATE.Value), Fields!Metric.Value, "MetricDataSet")

Let me know if I misunderstood the issue.



来源:https://stackoverflow.com/questions/31280298/ssrs-tablix-cell-calculation-based-on-rowgroup-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!