SSRS Grouping Aggregate - reporting-services

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.

Related

sorting a report by subreport values

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).

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.

Group by column & row in one part of expression, group by column only in another part of expression

I am trying to find a way to use the Group By functionality to create a table where the numerator of a fraction is grouped both by column and row, and the denominator is grouped only by column.
Here's my existing expression:
=Round(Sum(Fields!Days_In_Step.Value)/CountDistinct(Fields!ID.Value),1, MidpointRounding.AwayFromZero)
When grouped by rows (groupName) and columns (month/year) the numerator (Sum(Fields!Days_In_Step.Value)) gives me good data, but the denominator (CountDistinct(Fields!ID.Value)) is also grouped by row (groupName) and I don't want that.
I have a SQL solution but am trying to do this entire within SSRS expressions, if possible.
edit
Sample Data:
It would look like this. The background is that these groupings are counts of days and the "all" are counts of tickets, so we are trying to see who is sitting on their tickets longer.
Here is a mock-up including a sample data set using a pivot table:
Edit 2
Here is a full sample data set:
https://docs.google.com/spreadsheets/d/1rYPMcrLNB-FZN64Fn2-y3FtnM2iQo2VMH7YTdfiVnKM/edit?usp=sharing
I need to group on month as well as year, and I do not want to see "Exclude" in the group rows, however they cannot be filtered out of the tablix without being removed from the overall population, which is required for the denominator.
Your problem is caused by the scoping of aggregate functions. When you use aggregate function they run under the scope where it is placed in the tablix by default. In your case Sum() and CountDistinct() functions are running in both row groups (Owner Group) and column group (Month Group).
Fortunately, you can specify the scope that you want your aggregate function computes the aggregation, simply add the group name in the function:
CountDistinct(Fields!ID.Value,"MonthGroup")
The whole expression is like this:
=Round(Sum(Fields!Days_In_Step.Value)/
CountDistinct(Fields!ID.Value, "MonthGroup"),1, MidpointRounding.AwayFromZero)
Replace "MonthGroup" by the actual name of your group in columns
group.
This is result using the sample data you provided:
I've used this expression to show you how it is produced:
=Sum(Fields!Days.Value) & "/"
& CountDistinct(Fields!Ticket.Value,"MonthGroup") & "=" &
Sum(Fields!Days.Value)/CountDistinct(Fields!Ticket.Value,"MonthGroup")
Note my column group is named MonthGroup.
UPDATE: Scoping multiple groups in CountDistinct function.
Firstly I am not filtering the dataset, I prefer hide the Exclude rows using the below expression in the Hidden property of the Row Visibility window:
=IIF(Fields!Group.Value="Exclude" OR Fields!Group.Value="-1",true,false)
To count distinct id grouping by Month and Year but not by Group you can create a child group below Month group as you can see below:
My group is called Group2 and I used this expression in the Group on textbox.
=Fields!End_Month.Value & "-" & Fields!End_Year.Value
It will create a group per every Month-Year combination. When you create the group it will be added as a column group so you will have to delete the row so you will be prompted if you want to delete the group and row or delete the row only. Delete only the row leaving the group.
Now the expression you have to use is
=Round(Sum(Fields!Days.Value)/CountDistinct(Fields!ID.Value, "Group2"),1,MidpointRounding.AwayFromZero)
Replace Group2 by the name of the created group in your case.
This is the whole recreation of your scenario:
Let me know if this helps.

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)))

Difficult MS Access Query - how to combine them?

I am trying to build an access report based on data from multiple different tables within the database.
I have 3 columns which perform calculations, and I am wondering how to put this query together. All 3 columns deal with dates, but calculate them differently.
The first column retrieves the most recent date of action for a userid if the type of action is "B":
select pid, Max(date) as most_recent
from actions
where ref = 'B'
group by pid;
The second column performs a calculation based on 2 fields, one is a date and one is a number in months. I am unsure how to add these two fields so that the number is added to the date as a number of months.
what i have so far is:
select nummonths,Max(lastvisit) from users
the third column I need to select the first date thats in the future for each user (next appointment date), there will be dates before and after this date so its a little difficult:
select uid,date from visits
The code for the last 2 queries needs to be slightly modified, and I was wondering what the best approach would be to join these all together? A type of join?
If you need to build a report with data from the 3 queries, you will need related data to join them. In that case, please send the structure of the tables.
If you need to show 3 lists in one report, you can use subreports: create a new empty report. In design mode, you can add 3 subreports from the toolbox bar. To each of the subreport assign the record source property to the corresponding sql.
regards
I am unsure how to add these two fields so that the number is added to the date as a number of months.
Use the DateAdd() function:
SELECT DateAdd("m", 2, LastVisit) FROM ...
Results in a date two months from the LastVisit date.