Group on page count - ms-access

I have a report which is grouped on an ID field. Each grouping is roughly 1-3 pages depending on how much data Is pulled from the source.
Is there a way to group the report based on the page count of each section?
Example:
All Groups that are 3 pages
All Groups that are 2 pages
All Groups that are 1 page

AFAIK you can not access the number of pages since the grouping is done before the render of the page.
But, assuming you have a table T with a column ID being of a set of values v, which you group by, why not do a count of how many rows there are per value v and join that to you report source (or just use the HAVING clause)? You can maybe derive the number of pages by the number of members of each ID.
Like
ID value count
1 a 2
2 a 2
3 b 1
...

Related

SSRS Report - Badges

Is there an easy way to do a page of badges in an SSRS report? I am looking at 2 across and 3 down per page based on a list. I have built one so far of a single column using a list box but the problem is that it is not advancing to the next record and shows me the same record over and over until I get to the end of the count of total records in the dataset so I know I am doing something wrong. I am using Visual Studio 2017
I use a matrix when I am making a grid with boxes that go across and down.
First I add a ROW_NUMBER to the query to have the order in which to show the records. I subtract 1 so the values start with 0.
SELECT *, ROW_NUMBER()OVER(ORDER BY EFF_DATE) - 1 ROW_NUM
FROM BLAH_BLAH...
Then in SSRS, add 2 Calculated Fields to the dataset with the ROW_NUM.
The first is named ROW. It will have an integer with the row that the record will end up in.
=INT(Fields!ROW_NUM.Value / 2)
The second is COLUMN that will give the a column number.
=Fields!ROW_NUM.Value MOD 2
Then in the matrix, set the grouping based on the calculated fields.
COLUMN GROUP
Group and Sort by COLUMN
ROW GROUP
Group and Sort by ROW
The 2 can be changed to use whatever number of columns is needed.

Display value and number of duplicates in MySQL

I have a MySQL database row named ID and it goes
ID
18464762
3936573
3936573
3936573
374749502
374749502
374749502
374749502
374749502
3746325
9705732
9705732
9705732
9705732
476870382
476870382
3746574
37264
37264
And I want to make a MySQL Query that displays the information in two columns, the ID, and how many occurrences of the ID exist. That way I can sort it by number of occurrences.
The ideal output would be
id occurences
374749502 5
9705732 4
3936573 3
32764 2
476870382 2
18464762 1
3746325 1
3746574 1
This is just a small example as I have thousands of entries.
Everything I have already found from searching online tells me how to find which ids have duplicates, or the number of id's that have duplicates, but I have been unable to display the information like this.
Thank you in advance
You need to GROUP BY id, use aggregate function COUNT for counting occurences, and at the end order by second column.
SELECT id, COUNT(*) AS occurences
FROM your_tab
GROUP BY id
ORDER BY 2 DESC

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.

Populating with '0' when Data in SSRS Does not exist

I'm trying to create a report in SSRS where I have a matrix, which has gender as the column headings and specifically defined agegroups as the rows. The report is sorted by date (ie, the records being displayed are filtered by the modifedAt value). My problem is that i wish for all of the age group categories to be displayed, even if the dataset does not return any data for that row.
So, for example, if i set the date to be a date where there are no db rows where there are Age5-16 children in - I still want to display the category name, but just have the cells related to that row to display '0'. Instead, the report just drops the whole row because, obviously the query returns no data.
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together? I'm stuck here so any help is appreciated!
I can think of a few ways to do this:
DataSet level
Instead of just returning the relevant data in the underlying data in the DataSet, include all the categories you want to display in all cases.
e.g. For a database query it might be the difference between an inner and left join, i.e. going from something like:
select *
from AgeGroup
inner join MyData on ...
to:
select *
from AgeGroup
left join MyData on ...
So the report always has all the age groups to display. Where there are NULL values, just display 0.
I think this is the best option if you have control over the DataSet - you won't have to update your report at all, with luck the actual DataSet changes should be minimal, there is still only one DataSet call, and it's by far the simplest to maintain.
Hard code groups into the report
Here you include a table header row for each group you want to display, so these are always displayed in all cases.
Here you have some sort of conditional expression to display the values, e.g. For each group row it will be tailored to that group:
=Sum(IIf(Fields!AgeGroup.Value = "5-16", Fields!Amount.Value, Nothing)
This is not too flexible and will need updates as you change groups, and doesn't have as many options for layout. There is still only one DataSet call, so that is a plus.
Subreports
You can have a parent DataSet that displays one row for each age group, then embed a subreport in each row that displays the data you want for that row.
This allows you flexibility in layout but it will add complexity to the report(s) and will mean that you make a lot of DataSet calls that could be avoided with other options.
I know this is old, but I wanted to elaborate on Ian's section 1 above using joins at the dataset level. (His answer was super helpful to me for a report I'm working on.)
per op:
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together?
That is how I've handled it successfully, but you can do so without actually creating a separate dataset by using common table expressions (or temp tables, of course).
For these example tables:
AGE_Table
ID Group Group_Desc Toys
1 A 00-10 Teddy Bear
2 B 11-20 Video Game
3 C 21-30 Sports Car
4 D 31-40 Mansion
5 E 41-50 Jewelry
People_Table (filtered for whatever date)
ID Name Age Gender Age_Group
1 Ariel 07 F A
2 Brandon 23 M C
3 Chelsea 27 F C
4 Derek 06 M A
You want to see 2 results for the 00-10 row, 2 for the 21-30 row, and then still see rows for the other age groups even if there aren't any results.
We want to create a dataset with all the different age groupings and then join on it. Behold a solution using common table expressions:
with CTE_Age AS
(SELECT Distinct Age_Group from AGE_Table)
SELECT ID, Name, Age, Gender, CTE_Age.Age_Group FROM People_Table
RIGHT JOIN CTE_Age ON
People_Table.Age_Group = CTE_Age.Age_Group
This will return:
ID Name Age Gender Age_Group
1 Ariel 7 F A
4 Derek 6 M A
NULL NULL NULL NULL B
2 Brandon 23 M C
3 Chelsea 27 F C
NULL NULL NULL NULL D
NULL NULL NULL NULL E
Once you have that in your dataset, you can change NULL values to 0 on the report builder side -- I think in 2008R2 the default is just blank.

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.