简体   繁体   English

SSRS - 按多个值分组

[英]SSRS - Group By Multiple Values

I am trying to group by specific values of a field. 我试图按字段的特定值进行分组。 I have project information data populating, and I would like to group on electoral area field. 我有项目信息数据填充,我想分组选举区域。

However, I would like to group the values together in a specific way. 但是,我想以特定的方式将值组合在一起。 For example: 例如:

If the values are: 如果值是:

District of Invermere, City of Cranbrook, Town of Creston 因弗米尔区,克兰布鲁克市,克雷斯顿镇

Then group those projects in a group called "EAST" 然后将这些项目分组到一个名为“EAST”的组中

If the values are: 如果值是:

Village of Valemount, Village of New Denver, Village of Kaslo Valemount村,新丹佛村,Kaslo村

Then group those projects in a group called "WEST" 然后将这些项目分组到一个名为“WEST”的组中

Everything else group in "BASIN". “BASIN”中的其他所有组合。

So, far I have created a group and in the group properties I have put an expression in the "Group on" field: 所以,我创建了一个组,在组属性中,我在“Group on”字段中放置了一个表达式:

**=iif(Fields!cbt_electoralareaidname.Value = "District of Invermere" OR "City of Cranbrook" , "EAST" ,(iif(Fields!cbt_electoralareaidname.Value = "RDCK Area F" OR "Town of Creston", "WEST", "BASINWIDE")))**

But nothing is working... I know I am overthinking this, please HELP! 但没有任何工作......我知道我正在思考这个,请帮助!

UPDATE UPDATE

The following is sample data: 以下是示例数据:

  • Project Name 项目名
  • Project Description 项目描述
  • Location 地点
  • Electoral Area 选举区

It is retrieved and the layout is currently like this: 它被检索,布局目前是这样的:

项目细节

I also have the field Electoral Area, and that is the field I want to SORT/GROUP the data on but not using the SQL query because I do not want to aggregate, I want the details as they are and create Row Groups. 我也有字段选举区,这是我想要对数据进行排序/分组但不使用SQL查询的字段,因为我不想聚合,我想要详细信息并创建行组。 For the example below, I just want it to look like below: 对于下面的示例,我只想让它看起来如下所示:

排序

You can try something like this: 你可以尝试这样的事情:

Select ...
From ..
GROUP by 
case 
when city in ("city1","city2",...) then "west" 
When city in (...) Then "east"
Else "other"
End 

If you want to generate an extra field so you can group by later: 如果要生成额外的字段,以便稍后进行分组:

Select ..., 
case 
when city in ("city1","city2",...) then "west" 
When city in (...) Then "east"
Else "Basin"
End AS region
From ..

If you have many citys to define and the case ... end is out of control, you can create a table mapping each city to some region and do a join: 如果您要定义许多城市并且案例...结束失控,您可以创建一个表格,将每个城市映射到某个地区并进行连接:

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

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