ssrs count error getting 1's instead of total - reporting-services

Rookie mistake,
here it is:
I got Regions and MembersID, I grouped the regions and want to count the members. When I add the count(MembersID) instead of geeting the total members, I get a bunch of 1:
RegionA 1
1
1
RegionB
1
1
what I want:
RegionA
3
RegionB 2
what I did: Grouped Regions and Count[MembersID]
Please help!

It's a bit tough to tell what you actually need here.
In Group Header rows, you can use aggregate functions, which will look at all rows in that current scope.
Distinct MembersID count in group: =CountDistinct(Fields!MembersID.Value)
Total rows in group: =CountRows()
In detail rows, these aggregate functions will only report on the current rows, so =CountRows() will only ever return one; to get the number of rows in the group you need to set the scope of the function to the group level, e.g. something like =CountDistinct(Fields!MembersID.Value, "Group1") or =CountRows("Group1").
So based on a Dataset:
And a report which incorporates these aggregate function in the group header and detail rows:
You can get the following results:
If this is not sufficient you will need to supply your Dataset details, some sample data and how you need this sample data presented.

Related

SSRS conditional expression help to count distinct by group

I've got a report where I want to return the distinct count of [Above MRL]
e.g. Canola counts 13 being the sum of the number of times all the Sample IDs are [Above MRL].
Sample ID 330174 has a value of two, because this sample has been above MRL twice. I only want to count Sample ID 330174 once. Then roll this number up to the Canola level. Then I want to roll these products like almond, apples, canola to the plant level. So everything needs to be counted only once and summed.
How do I achieve this with an expression?
It sounds like you want to count the number of Sample IDs if the Sample Above MR is equal to 1.
=CountDistinct(IIF(Fields!AboveMRL.Value = 1, Fields!SampleID.Value, NOTHING))
This will check if the Sample if AboveMRL and, if so, count the ID. NOTHING is like NULL and is not counted in a Count Distinct calculation. If there are two of the same sample ID, it will only be counted once.

How to Combine Fields from Two Datasets SSRS?

I am working on a report to show the total number of hours an employee spent working. Our company tracks labor hours by Service Request and Work Order so I need to bring totals for each into the report.
I created two datasets- one for Work Orders and one for Service Requests. Ideally, I would like to combine the total number of Work Order hours with the total number of Service Request hours and present that number listed by employeeID since both datasets have the employeeID field.
I thought it would be as simple as:
=(SUM(Fields!TOTALHOURS_WO.Value, "DataSet1") + SUM(Fields!TOTALHOURS_SR.Value, "DataSet2"))
I don't get an error, however, I am getting a number which repeats for each employee so I know I'm doing something wrong.
Any help is greatly appreciated.
Mal,
As #StevenWhite mentioned, LOOKUP is probably the function you are looking for.
Here is an example for you. For the example datasets:
EmployeeID | TOTALHOURS_WO
-----------------------------------
123 | 12
456 | 3
EmployeeNum| TOTALHOURS_SR
-----------------------------------
123 | 2
456 | 5
You will note that each table in a SSRS report needs a DataSet assigned to it. I will assume your table is using our first DataSet, which we will name "DataSet1". The second dataset above will be "DataSet2".
For your total hours you will use an expression. It should look something like this:
=TOTALHOURS_WO + LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2")
So you will be adding the TOTALHOURS_WO from your local dataset to the result from the LOOKUP function. What lookup is doing is taking the first field from your local dataset, finding a match in the dataset provided to the function (as a string), and returning the field from the row it matched to. The last parameter is the dataset to search.
Just in case you get an error... it's always a good idea to cast data to the type you want to work with in case it comes in wrong. So...
=CINT(TOTALHOURS_WO) + CINT(LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2"))
This assumes you have a one to one match on employee ID. If you have to SUM both fields you can try this:
=SUM(CINT(TOTALHOURS_WO)) + SUM(LOOKUPSET(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, CINT(Fields!TOTALHOURS_SR.Value), "DataSet2"))
SUM for TOTALHOURS_WO will give you the SUM in your current table group (so make sure you are grouping by staff ID in the table). It will then add it to the SUM of LOOKUPSET. LOOKUPSET works the same as lookup but returns an array of matches instead of the first.
Hope this helps.

SQL Report Builder for Survey Data

I have a large dataset with People's names and their Rating from 1 to 5.
Then I made a query that summarizes this data for PersonA:
Rating Count
------- ------
1 4
2 6
3 1
4 0
5 2
I just need to know how to show this on my report.
I have made a cell for each rating and need to put in an expression that says "If Rating=1, show count for rating 1".
I tried using =IIf(Fields!Rating.Value = 1, Fields!Count.Value, 0) but this didn't work.
I'm not sure why you would need an expression like that, based on your description of the dataset it sounds like you already have two columns of data for rating and count, so you could use a tablix (table), with columns:
Rating Count
which would list all the rating values and associated count values, similar to the example result in your question.

Reporting Services: Show top N Rows with Grouping

I am trying to show the top 10 rows in my report. I can do this by setting the following expression for the Visibility of the row group:
=IIF(RowNumber(Nothing) <= 10, false, true)
and then sorting the table on the top numbers.
In my query I get two rows for each result, with different results. The problem is that I want to group these rows into one row in the report without losing the count for top X rows. But when I group on the name in my report in Visual Studio, it only shows every row one time and the count for X rows get incorrect. Sometimes I have the same name once and sometimes twice. I have tried to set the expression to 20 rows, but then I might get 12 rows sometimes and 10 rows sometimes, depending on how many rows for each name my query returns.
Thanks in advance,
Sara
It sounds like you need to top N after you group. Can you group in you query?

How to do SUM(VacancyID) without Duplicates while also showing Count(VacancyStartID) in the same Group?

In SSRS 2005 I am reporting on all available posts by regional office, listed by region,office,vacancyID.
I then display a total per office on how many people started in a particular vacancyID by doing a Count(VacancyStartID).
In the same group row with the Count(VacancyStartID) I need to display SUM(VacancyID).
However at present this does not give the correct SUM, because some vacancies have multiple VacancyStartID's and hence the vacancyID is listed few times, like so:
office vacancyID Number_of_vacancies VacancyStartID (person who started a job)
1 1 2 4567
1 1 2 5678
Totals: 4 (needs to be 2) 2
P.S. Note:These questions are not applicable in this instance:
How can I remove duplicate rows?
How do I remove "duplicate" rows from a view?
Using multiple COUNTs and SUMs in a single SQL statement
If it's in the Underlying SQL Server call...
You can do ...SUM(DISTINCT VacancyID)... like you can COUNT (DISTINCT ..)
Edit:
SELECT
col1, col2, SUM(DISTINCT Number_of_vacancies) as foo, COUNT (VacancyStartID) as bar
FROM
MyView
...
If it's in the table or for a cell in the report, then there is no equivalent in the SSRS SUM function.
Do some grouping already in your query and then make a group with a simple Count in SSRS.