0

I'm trying to do a reasonably simply report but I'm new to this and struggling.

I have two tables, Properties and Incidents.

In the Properties Table I have an ID, the Name of the property (Name) and Number of rooms (NoOfRooms).

In the Incidents table I have the ID, Property that it relates to(PropertyID),DateOpened, DateClosed and Status.

In the report I've managed to get it to show me the number of incidents per property and then the number of incidents closed per bed space.

However, in the summary what I want it to do is total up all of the incidents in that month, which I've done. But then divide that number by the total number of beds.

Where the problem is coming in is it's adding up all of the number of beds multiple times.

So if the data looks like this:

Property Name   IncidentID      No of Beds
Property1       1               100
Property1       2               100
Property2       3               200
Property2       4               200
Property2       5               200

I Have it showing:

Propery Name    No Of Incidents      Incidents / Bed
Property1       2                    0.02
Property2       3                    01015

But I can't get it to show the summary which should be:

No of Incidents          Incidents / Bed
5                        5/300 = 0.016666667

I have the No of incidents that's ok, it's just the final incidents / bed where it recognises there's only 300 beds and not 800.

4

1 回答 1

0

我认为您可能很难在报告级别执行此操作。

我会通过扩展底层数据集来解决这个问题:

Property Name   IncidentID      No of Beds  Total Beds
Property1       1               100         300
Property1       2               100         300
Property2       3               200         300
Property2       4               200         300
Property2       5               200         300

如果您只是从数据库中提取它,那么 SQL 应该不会太难,并且后续的报告级代码也应该相当简单。

最终,SSSRS 难以处理这些类型的聚合,您在组级别进行聚合(获取不同床位值),然后在更高级别应用另一个聚合(不同床位值的总和)。

SSRS 2008 R2 确实提供了聚合选项,因此如果您使用的是 2008 R2,则可以使用以下表达式来执行此操作:

=CountRows() / Sum(Max(Fields!NoOfBeds.Value, "PropertyName"))

其中PropertyName是组的名称。

但是对于 2008 年,您最好将Total Beds添加到 Dataset 级别。

此外,用户@Tom Jenkin 提出了一个很好的观点;如果您只对属性级别的详细信息感兴趣,您可以将您的数据集更改为已经聚合,例如,如果它是由 SQL 语句生成的,则使用GROUP BY仅返回上述数据的两行;这也很合适。

评论后编辑:

我根据您的示例数据集创建了一份报告:

在此处输入图像描述

在此处输入图像描述

您可以看到已经创建了一个名为PropertyName的行组。

Total Beds的表达式是=Sum(Max(Fields!NoOfBeds.Value, "PropertyName"))

最终百分比的表达式是

=CountRows() / Sum(Max(Fields!NoOfBeds.Value, "PropertyName"))

如上。

这给出了所需的结果:

在此处输入图像描述

于 2013-04-17T16:04:08.897 回答