Sum of distinct in SSRS - reporting-services

I have to get distinct rows sum in SSRS expression.
**StudentId TestScoreMath CurriculumEnrolled EnrollStatus**
100 200 Nursing Enrolled
100 200 Physical Enrolled
200 100 Tech Enrolled
Total Student TestScoreMath should be 300 not 400. I tried using the expression
=Sum(Fields!TestScoreMath .Value, "table1_Group3")
How can I SUM the value of TestScore of distinct students? I need this only in SSRS.

In SSRS 2005, this is not too easy. I would add embedded code to keep a running total. You can have the custom code to check to see if the current student ID matches the last. If so, then don't add another test score to the total. Or you could group by Student ID and call your custom code only in the header or footer of that group.
This sample shows totaling all rows: you'll need to add to this to track the studentID.

Related

SSRS - Percentage Totals Row

I am trying to build an SSRS report that has a column based on a percentage:
AgentSales AgentCommission Commission
20 .25 5
33 .12 3.96
46 .76 34.96
Totals: 99 [Unknown Calculation]
However, where I am having problems is I need to get what would be the totals column? How would I calculate the Commission so that the number shown in [Unknown Calculation] to display what I assume would be the average commission?
Commission column is simply AgentSales * AgentCommission. The total commission wouldn't be a SUM(Commission), but would more or less be the average commission for all agents.
Assuming you want to calculate the weighted average commission then I would calculate it like this..
Expression 1: is simple as per your sample.
=Fields!AgentSales.Value * Fields!AgentCommission.Value
Expression 2: is the sum of the results of expression 1
=SUM(Fields!AgentSales.Value * Fields!AgentCommission.Value)
Expression 3: is the expression 2 divided by the sum of agent sales
=(SUM(Fields!AgentSales.Value * Fields!AgentCommission.Value))
/
SUM(Fields!AgentSales.Value)
The other cells should be self explanatory...
When we run the report we get the following.
If this is not what you wanted, then please edit your question to show the desired result and how you arrived at that result.
EDIT AFTER UPDATE FROM OP
If you want the cell marked "2" in my sample to be an average of the values above then simpley change it to
=AVG(Fields!AgentSales.Value * Fields!AgentCommission.Value)

Merging multiple Rows in ssrs report to a single one

I need help regarding SSRS Reporting my data is Coming from a Query and I also have added the Column Group Named as Subject Name Showing on the top of the Table() Also Added ApplicantID as Row Group and FName as a Row Group in the Report to fulfill my requirement that was just to show
Since I am not Sure how many subjects a user can select its all decide on the run time so i did added the Subject name as a column group
All the Subject records in a single row for a specific ApplicantId Instead of showing below my Requirement is
It Should looks like as a table
Anatomy Surgery Zoology
Part ISt
14 Hanan Qureshi Iqbal Qureshi 15.00 20.00 10.00
15 Tasneem Alam Imtiaz Alam 30.00 10.00 20.00
etc instead of Showing in a seperate row it should show in a single row
Details group is your problem as #hemanth said you need to remove this and add in an aggregate function (max, min, sum, average) any will work since there is only one value for each SubjectName, Obtained Mark Combo. this will give you all the marks on one line for each applicant.

ssrs count error getting 1's instead of total

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.

Microsoft Access 2010 - Filtering by a caculated field in a query-based report

Ok, here's the condensed form. I have three main tables to draw data from:
StudentData - PK is the student's ID Number. Contains contact info, their current status ('00' for none, 'P' for Probation, 'S' for Suspension), and cumulative gpa data.
CourseData - PK is the CRN. Contains just the abbreviated subject and the course number (IE ECON 200)
StudentCourses - PK is an AutoNum. Many-to-Many relationship table between StudentData and CourseData. Also contains stats for the particular student's class (grade, credit hours, etc).
So some sample data would look like:
-
StudentData
ID: 12345678
Name: John Doe; ...[Other contact info]; 00; CumCreditHours: 100; CumCoursePoints: 190
-
CourseData
CRN: 0001; Abbrev: ECON; CourseNumber: 101
CRN: 0002; Abbrev: CSCI; CourseNumber 201
-
StudentCourses
AutoNum: 1
StudentID: 12345678; CRN: 0001; Grade: A-; Credits: 3
AutoNum: 2
StudentID 12345678; CRN: 0002; Grade: B; Credits: 3
-
At this point, this is how I have things set up:
First, a query runs that finds all of the courses a student takes and converts the letter grades into a point value. Another query based on the first sums the point totals and the credit hours. A third query takes those totals and calculates the GPA by dividing their point total by the credit hour total.
Separately, a query runs that calculates the student's cumulative GPA by taking their cumulative points and hours from the StudentData table (again dividing the points by the hours).
Then, another query takes both the semester GPA, cumulative GPA, current status, and cumulative credit hours and calculates the recommended action for the student. So for our example data it would look like:
_
SemesterGPA: 3.33; CumulativeGPA: 1.90; CurrentStatus: 00; CumulativeCreditHours: 100
_
I have the formula to determine their recommended action set up as a series of nested IIF statements that looks like:
IIf([CurrentStatus]="00" And [CumulativeGPA]<2 And [CumulativeCreditHours]>=12 And [CumulativeCreditHours]<=23,"PFY",IIf([CurrentStatus]="00" And [CumulativeGPA]>=1.7 And [CumulativeGPA]<=1.99 And [CumulativeCreditHours]>=24,"P",IIf([CurrentStatus]="00 " And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]<12,"W",IIf([CurrentStatus]="00" And [CumulativeGPA]>=2 And [CumulativeGPA]<=2.5 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"WUP",IIf([CurrentStatus]="00" And [CumulativeGPA]<1.7 And [CumulativeCreditHours]>=24,"SUSP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]>=2 And [CumulativeCreditHours]>=12,"CP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"SPCP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [CumulativeCreditHours]>=12,"RP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,IIf(IsNull([PriorSuspension]),"S(FD)","D(SD)"),"None")))))))))
For our example, John Doe's recommended action would be 'P' since his current status is 00, he has over 24 cumulative credits, and his cumulative gpa is between 1.7 and 1.99.
Now for the problem: I would like to be able to make a report that can filter by the recommended action. I've detailed the issues I've had previously, but in short, the way I have the reports set up now (with the information being displayed in a sub-report inside a report that is based on the StudentData table to provide the aforementioned queries with the StudentID) doesn't allow me to do this because the field I want to filter by exists in the sub-report and not the main report (and you can't set the filter properties for a sub-report).
Any ideas?
Ok, I've got this to work now. I realized that as I was calculating the semester GPAs that I had grouped the results together by ID at some point during the process. This allowed me to remove the part of the initial query that grabbed the ID number from the form. Since the last query in the process linked everything together by student ID, the individual records held all of the information I needed and everything fell into place after that.
I half expected something simple like this to be the answer to my problem, but I'm still disappointed that it took me this long to figure it out...
Anyway, thanks to anyone who might have been thinking of possible solutions for this problem.

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.