Report subtotals without grouping

久未见 提交于 2019-12-14 02:12:48

问题


Might be easier to show what I am trying to return and then explain.

REGION  STATE  SALES
------  -----  -----
WEST    WA     $ 200
EAST    VA     $ 175
WEST    CA     $ 100
EAST    NY     $  50
NORTH   MI     $  25
NORTH   WI     $  20
  WEST SUBTOTAL: $300
  EAST SUBTOTAL: $225
 NORTH SUBTOTAL: $ 45
    GRAND TOTAL:$570

While the example above isn't my exact business case, it's close enough to simplify the question.

So, using the sample data above, my report can be ran by one or more regions. In this example, I ran it for regions west, east and south. The report sorts the detail data by total sales, with the highest sales at the top. Following the detail data, I'd like to get a subtotal of the regions' totals. If I ran for two regions, then I'd get two subtotal lines. Then finally, a grand total.

This would be easy if I was grouping by region, but I'm not; I want the detail to remain sorted by sales regardless of region. How can I achieve this? The tricky part is the dynamic number of subtotal lines.

I'm running SSRS 2012.


回答1:


You can do this in the one table based on your existing Dataset using an Adjacent Group based on REGION.

Say you have a simple table like:

To add the REGION subtotals, right click on the detail row and select Add Group -> Adjacent Below...:

The end result should look something like:

i.e. the group row is directly after all the detail rows.

In my case I set the expression to =Fields!REGION.Value & " Sub Total:" and set the new group to sort by =Sum(Fields!SALES.Value) from high to low.

Seems to work as required, give or take some formatting:



来源:https://stackoverflow.com/questions/17682757/report-subtotals-without-grouping

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