sorting a report by subreport values - reporting-services

I have a subreport that provides items and their value, with a sum of the value at the bottom. I would like to sort my main report, which is the owner of the items, by the total sum of the item value.
I have a main report that supplies the user with a persons name and contact information. I have built a sub report that takes the person's ID and displays the name and value of items associated with them. The subreport has a sum of the items. I would like to sort this report so that the highest total value is at the top. I'm new to working with sub reports in SSRS so any help would be appreciated!
this is my report -> type and balance are the sub report. I know that these are already sorted, but that is just coincidence and I have about a thousand rows that need to be sorted by total balance

I assume that the subreport is in a tablix of some kind?
If so then the usual process is to include the value you want to sort by in the dataset that drives the tablix.
So the dataset for tablix containing the subreport might look something like
SELECT *
FROM (
SELECT personID, SUM(transactionvalues) as SortValue
GROUP BY personID
) q
ORDER BY q.SortValue DESC
Now you can just sort your tablix by the SortValue

You also can apply the sorting from the report side. If your Sum() has the following expression in your tablix,
=Sum(Fields!Balance.Value)
you can add the exact same expression in the Tablix Properties > Sorting > Add (with the option from A to Z or Z to A).

Related

Group totals in tablix - only returning first value

I have a tablix that is grouped (row group) according to variety name, and year planted.
Itemized, each plot has an area, and without grouping, this is showing up correctly in the report. With grouping, per variety name and year planted, it only returns the first value, rather than the total of all values within the groups.
I've tried Fields!NewArea.Value, and SUM(Fields!NewArea.Value) - it still returns on the first record's area, rather than the sum areas.
Can someone tell me how to achieve the sum, per group?
If you right-click on your rowgroup in the grouping pane below the main design window, then choose Add Total Before/After. It should create sums in the new total row automatically, but if not then the expression just needs to be
=SUM(Fields!myFieldName.Value)
The SUM() is evaluated at the row context level, so in your case it will be the sum of the values in the same row group.

how to group and filter on aggregate in SSRS

I have a requirement to report the number of people who have more than one record in the dataset for my SSRS report and I can't quite get how to filter on the grouping.
So if the dataset results are:
ID PersonID FileID
1 1234 abc
2 7890 ade
3 5647 aer
4 1234 xyz
I would like to report 1. There is one person who has more than 1 record.
Is there an expression or something I can use to do this?
Thank you.
You can use LookupSet and CountDistinct function to get the required count, however you will need the textbox used to show the calculation be in a scope.
If you want to show the number of persons with more than one record as a total in your table use this expression:
=CountDistinct(
IIF(
LookupSet(
Fields!PersonID.Value,Fields!PersonID.Value,
Fields!ID.Value,"DataSetName"
).Length>1,Fields!PersonID.Value,Nothing)
)
Set it outside any group scope:
However if you want to show the number of persons with more than one record outside your tablix in a textbox, you can add an additional tablix and delete the necessary rows and columns to leave only one textbox then set the dataset property to the dataset name you are using and use the same expression.
It should produce:
Note my dataset has more rows to ilustrate the functionality. In the right side there is only one textbox with the count.
Let me know if this helps.
If you want the result to be something like shown below.
Steps:
Create a group on Person ID
Right Click on Group > Add Total > Before
Add a column and put =Count(Fields!PersonID.Value)
If you want to display only Persons having more than one, set the visibility property of the tablix row.

SSRS Grouping Aggregate

I'm having an issue creating some grouping in SSRS. I can't use SQL.
Basically I have a set of data I want to turn into a pivot or summary table. I can SUM revenue by ownerID no problem, but they have some teaming and filters on their report I can't replicate. This is the basic table:
Employee Quote Revenue
User1 SUM by ownerID
User2 SUM by ownerID
User3 SUM by ownerID
User4 SUM by ownerID
User5 SUM by ownerID
User 6 SUM by ownerID
This is what they would like to measure
Teaming/Filter Quote Revenue
User 1 & User 2 SUM by Group
User 3 & User 4 SUM by Group
User 5 where customer type=1 SUM by Filter
User 5 where customer type=2 SUM by Filter
User 6 SUM by Owner ID
I've used SUM by a group name and I've tried SUM IIF but they either don't work or I get the revenue on separate rows. Would appreciate any advice.
Thank you.
My approach here would be to use a one row Tablix for each measure. That way, you can set the filter, and grouping for each scenario in its own Tablix, instead of attempting to do this in one. This keeps with the no SQL restriction. As far as display on the report, you can align each Tablix, and hide the headers, so it looks like one table in the end.
It’s not the most elegant solution in the world, but it should work.
More detail for one of the measures (User 1 and User 2 revenue):
Add a Tablix to the report
In the Tablix properties, set the dataset name to proper dataset
In the Filters properties for the Tablix, set the filter to what is need for the specific measure. You will have to use the In operator for the measures where you are teaming more than one user. In this case it will be something like “User1”, “User2” for the Value of a filter where the Expression is UserID, and the Operator is In. SSRS will change what the Value looks like in the designer, so you may have to play around with it duplicating quotes
In the Row Groups pane, for the (Details) row group, change the Group Properties group expression to use a field in the dataset that each row in the filter shares. Maybe a date, or a quote number in this case. You are not going to display this value so what it is is not important, just as long as it is the same for each row in the data you are filtering on.
In the first column of the Tablix, set the detail value to a string describing what you are showing, “User 1 and User 2”, in this instance.
In the second column of the Tablix, make the expression the sum of the revenue.
=Sum(Fields!revenue.Value)
Hide the header row
Run the report
I know this is a lot, but once you do one, you can copy and paste the Tablix, and adjust to new copy for the next measure. Hopefully, you don’t have a ton of measures! If you do, then a really need to think about doing this with SQL.

SSRS matrix insert column outside group only shows first value from dataset?

In SSRS report I have the Matrix with one column groups (i.e. week day name) and row group by week_date and Analysis_Name. When I render report, it only shows like first DOC_ID in outside group. Any idea how to show all DOC_ID code in outside group?
Thanks.

Error in finding sum of a group and Conditional Summing in SSRS Reports

I have an SSRS Report, in the database there is a column by name Total_running_hours.
There are more than one record for a single Cycle_number like more than 1 row with same Cycle_number but different Block_numbers and the value in Total_running_hours field will be same for all the rows with same Cycle_number. Eg. 1 Cycle number with 4 diff block_numbers contain same Total_running_hours for all 4 rows.
Now the problem is, in the group footer if I put this field then it will show the Total_running_hours value only once which is correct, but my final requirement is,
I need to get the sum of this field in the Report footer which need to display the sum group wise. No matter how many rows are there for a single Cycle_number it has to take only once and display the result.
I tried in different ways like
=sum(ReportItems!textbox204.Value) // name of text box in Group footer
Error: Report item expressions can only refer to other report items
within the same grouping scope or a containing grouping scope.
=sum(Fields!total_running_hours.Value,Group_name)
Error: The scope parameter must be set to a string constant that is
equal to either the name of a containing group, the name of a
containing data region, or the name of a data set.
Can any one please help me in getting the sum Group wise
Thank you in advance.
I found solution for this Problem.
We cannot simply sum the Total_Running_hours value as this would give us duplicates and the incorrect answer. We cannot sum the reporting services group as it goes out of scope
There is no SUM DISTINCT available in Reporting Services 2005 so we can't get the distinct value that way.
Since the query may not return a particular Cycle_Number Type we cannot use that as a filter.
The solution found was to add a column of the row number within a windowed set partitioned by the Cycle_Number like this
ROW_NUMBER() OVER (PARTITION BY Cycle_Number ORDER BY Cycle_Number ) AS 'RowNumber'
Then in the reports’ footer total column we put an expression that only takes the first row’s value to sum and converts all other rows to zero in that windowed set.
=SUM(IIF(Fields!RowNumber.Value=1,Fields!Total_Running_hours.Value,0))
After using this if u found any error in textbox like #Error
Then try this
=SUM(IIF(Fields!RowNumber.Value=1,CDbl(Fields!Total_Running_hours.Value),CDbl(0.0)))