Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

reporting services - How to get total of top 10 sales in SSRS 2012

I am taking Top 10 of Sales Volume grouped by Product categories in SSRS 2012. I need the total of these top 10 but it shows the complete total. I cant do it on dataset level as I need the complete dataset for other parts in the report. I tried the solution as given in MSDNlink but that didn't help either. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This sort of approach does actually work very well.

You haven't given any idea of what your data/metadata is like, but the concepts can be explained with a simple example. Consider the following data:

enter image description here

We will make a simple report based on this, grouped by the grp column:

enter image description here

Sort the groups by total val, from highest to lowest:

enter image description here

To get the running rank and the running total, we use the RunningValue function.

To get the Group Rank, use:

=RunningValue(Fields!grp.Value, CountDistinct, Nothing)

To get the running total use:

=RunningValue(Fields!val.Value, Sum, Nothing)

Finally, we need to display a total for the Top N values; in this case I'm displaying the top 2.

For the second group detail row, use the following Row Visibility expression:

=IIf(RunningValue(Fields!grp.Value, CountDistinct, Nothing) = 2, false, true)

That is, only display this row when there have been two groups, i.e. top 2. You could change the value as required.

This shows us one total row as required:

enter image description here

You need to apply these concepts to your data. If you're still having issues, I suggest trying to replicate my results with the above data/code to make sure you understand all the concepts involved.

Edit after comment:

For situations where there are fewer than N groups but you still want to display the last total, you need to add an extra check to the Top N row Row Visibility expression, something like:

=IIf(RunningValue(Fields!grp.Value, CountDistinct, Nothing) = 10
    or (RunningValue(Fields!grp.Value, CountDistinct, Nothing) = CountDistinct(Fields!grp.Value, "DataSet1") and CountDistinct(Fields!grp.Value, "DataSet1") < 10)
  , false
  , true)

So now the expression will show the for the 10th row, or if the total number of groups in the DataSet are less than 10, it will show for the last group row.

It's a bit more complicated but it has worked for me in the past; depending on your data and report setup you might need to play around with the Scope a bit to get it working in your environment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...