How to keep two dataset(grouping on each dataset) on one page - reporting-services

I have a requirement on which i need to show calender for each month with days on it and below this i need to show count for different services for that particular month. For this i have created two datasets
1> For the calender one
2> Different services for each month. Now I am not sure how to keep these two data sets on one page means
suppose its january month, so i need to show the calender for the January month and the total sevices for january month on one page and in the second page it will be show these two for februray month and it will go on. The number of months is controlled by a parameter .
What i have done now ?
For the 1st dataset the group is there and i have put page break after the group. And for the 2nd dataset, i have the group and put a page break after the group.
Please suggest how can i put these datasets on one page ( both are having group on the basis of month).
Thanks in advance.
Regards
Subrat

Here's a quick example.
NOTE: I'm using the AdventureWorks sample database here..
First we create the subreport. This will be a standard report but it will only produce results for a single month in our case. In this example I only pass in the month number as a parameter but obviously you might need to change that to pass in a year and/or other information.
I created a new report called Month Sub Report
I created two datasets that will give me sales by person and sales by territory for the same month. The queries I used are as follows.
-- query for dsSalesByPerson
select MONTH(OrderDate) as MonthNumber, SalesPersonID, p.LoginID , SUM(TotalDue) as Amount
from Sales.SalesOrderHeader s
join HumanResources.Employee p on s.SalesPersonID = p.BusinessEntityID
where datepart(yy, OrderDate) = 2013
and MONTH(OrderDate) = #MonthNumber
GROUP BY MONTH(OrderDate), SalesPersonID, p.LoginID
-- query for dsSalesByTerritory
select MONTH(OrderDate) as MonthNumber, t.Name as Terrotory , SUM(TotalDue) as Amount
from Sales.SalesOrderHeader s
join sales.Customer c on s.CustomerID = c.CustomerID
join sales.SalesTerritory t on c.TerritoryID = t.TerritoryID
where datepart(yy, OrderDate) = 2013
and MONTH(OrderDate) = #MonthNumber
GROUP BY MONTH(OrderDate), t.name
Note These both use the same parameter name with the EXACT same spelling, including case. As the create the datasets the parameter will be automatically created. If the name is the same on both databasets, only 1 parameter will be created which is what we want.
Next I added two simple tables and a textbox that looks like a header (actual headers don't work in subreports)
The final design looked like this.
When I run the subreport I get something like this.
Save and close this report design....
Next, create a new report, in this example I called it Month Master Report.
I created dataset called dsMonths with a list of months in (MonthNumber and MonthName) that we will use in our main report parameter to allow users to chose the months they want to report on.
I set the available values to point to our dsMonths dataset query and set it to allow multiple values (leave type as text)
Next create another dataset called dsMain. The query for this dataset needs to return a unique list of monthnumbers from your database so it might look something like
select DISTINCT MONTH(OrderDate) as MonthNumber
from Sales.SalesOrderHeader s
where datepart(yy, OrderDate) = 2013
and MONTH(OrderDate) IN (#Months)
ORDER BY MONTH(OrderDate)
Note: We use IN here as we are passing a list of #Months in.
Next, insert a table
Set the Dataset property og the table to dsMain
Next, remove the header row and all the column except 1.
Your table should have just a single 'cell' remaining. In this cell, right-click and insert a subreport.
Right-click the sub-report placeholder and choose properties.
Set the subreport used to be your subreport created earlier (i.e. Month Sub Report)
Click the parameters tab and then click "Add". Choose "MonthNumber" from under the name dropdown and your monthnumber fields from the value drop down list.
Next, double-click the "(Details)" row group nuder the main design window, click "Page Breaks" and select "Between each instance"
FINALLY! Mover the table to the top left corner of the page and shirk the report body so there is not lots of space around it (or this can cause unexpected page breaks)
When we run the report and choose a few Months we get the following, with each selected month on a new page (I'm only showing the last page in this image)
Hopefully that will give you enough to solve your issue.

Related

SSRS Current Document Map Display

I have a report that has document map on two columns...
I am trying to display the currently selected data (CAF SA -> PP5566) on its own page (using page breaks between groups) with the report name and code above the table of data, an example show below with the arrows:
So if I click the next code it will change data accordingly:
Here is how I would probably do it based on what I know.
The following example uses the Microsoft supplied Northwind sample database in case you want to reproduce this.
First I created a dataset pointing to the Northwind database using the query
SELECT DISTINCT
r.RegionID, r.RegionDescription
, t.TerritoryID, t.TerritoryDescription
, e.EmployeeID, e.FirstName, e.LastName
, c.CustomerID, c.CompanyName
FROM Region r
join Territories t on r.RegionID = t.RegionID
join EmployeeTerritories et on t.TerritoryID = et.TerritoryID
join Employees e on et.EmployeeID = e.EmployeeID
join Orders o on e.EmployeeID = o.EmployeeID
join Customers c on o.CustomerID = c.CustomerID
This will give us Region (the top group level), Territory (second group level) and some employee names and customer names which we can use in the detail part.
Next, added a tablix (table) and dragged the first name, last name & company name onto it. This will be the details row.
Next I right-clicked the details group in the row group panel and chose 'Add Group => Parent Group', set the group by to 'TerritoryDescription' and checked the 'Add group header' option before clicking OK.
Next I right clicked on the new TerritoryDescription group and repeated the above, this time using 'RegionDescription'
On territory row I added some static text into the 3rd column (under FirstName) and the territory description field as the expression for the 4th column (under last name). Now right-click on Territory static text you just added and choose "Insert Row => Inside group Above". Add static "Region" text and region field into column 3 and 4 respectively
I added a page header and footer just to it looks clearer when viewing on screen.
Next delete the first two columns as we no longer need these, select 'delete column only' if prompted.
Now double-click the TerritoryDescrition group in the row groups panel, click 'Advanced' and set the document map to 'TerritoryDescription'.
Repeat this for the RegionDescription row group selecting 'RegionDescription' this time for the document map.
The final design looked like this...
I set the report 'InteractiveSize' height to 15cm for clarity.
When the report is run I get this..
If I drill down to a differnt Region and Territory, I get this..

SSRS Report with groups and page breaks

I am trying to write an SSRS report where the output is grouped by team, with each team starting on a new page, and on a new tab when the report is output to Excel. I want the column headers to repeat each time there is a new team, and at the top of each page if one team's data spans more than one page.
My test data is generated by the following code:
WITH
team_list(team_id,team) AS
(
SELECT 1, 'red'
UNION ALL SELECT 2, 'orange'
UNION ALL SELECT 3, 'yellow'
UNION ALL SELECT 4, 'green'
),
results1(result_value1) AS
(
SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
),
results2(result_value2) AS
(
SELECT 7*result_value1
FROM results1
),
main_query(id, team, value1, value2) AS
(
SELECT
tl.team_id
, tl.team
, r1.result_value1+20
, r2.result_value2
FROM
team_list tl CROSS JOIN results1 r1 CROSS JOIN results2 r2
WHERE
r1.result_value1 < tl.team_id+2
)
SELECT * FROM main_query
I want the report to look like this:
I inserted a Tablix with three columns: id, value1 and value2. I right-clicked on Details under "Row Groups", and did Add Group>Parent Group, Group by Team. I did not tick either "Add group header" or "Add group footer".
I clicked on Team under "Row Groups". Then in the Properties Window, which was showing "Tablix Member", I expanded Group and then Page Break, and set Page Break to Between. I also set PageName to Fields!team.Value.
To get the column headers to repeat, I clicked on the down arrow next to "Column Groups" and chose Advanced Mode. I clicked on the second occurrence of Static under "Row Groups" and in the Properties pane, set RepeatOnNewPage to True. I now had a report with a page break between teams, and it repeats the column headers on every page. When I exported it I got a tab for every team with the team name on it. Good.
Now, I do not want the first column of the table, Team. So I right-clicked the column and chose Delete Columns, then Delete Columns Only. I saw that under "Row Groups" the top "Static" had disappeared. My report no longer repeated the column headers on every page.
I tried hiding the two cells in the first column of the table, and this seemed to give the desired effect, apart from indenting the table to the right. I tried to set the width of this column to zero, which does not seem to be possible. When I exported the report I got a very narrow Column A. Is there any way of getting rid of this column altogether, while still having repeating column headers?
For my team heading, I inserted a row above the top row of the Tablix. I merged the three cells above my column headings. I right-clicked and added the expression ="Team " & Fields!team.Value. This displayed "Team red" for all the teams, instead of changing on each page. How can I make a heading row that will show the correct team name for each group?
You need an extra row in the team group. The easiest way is to do this is to add a header when you added your team group.
So in the 1st paragraph of your step-by-step..
from Details to Add Group -> Parent Group, select Team and check the add header option.
Double-click the new Team row group in the row group panel and set page breaks to between
Now you will have three rows in the table, ignore the fact that rows 2 and three are merged in column 1, we'll get rid of that once everything else is done.
Right-Click on one of the cells in row 2 (e.g. column 2 row 2) and choose Insert Row -> Inside Group - Above.
the table will look something like this..
Next copy the column hedaers (id, value1 and value2) to hte row direclty above the cells with the actual data in (should be row 3).
Then in row 2 select the three cells above your data column and merge them.
Select team as the field for this merged cell (or your expression)
It should now look something like..
Now delete the first row and first column as we don't need these anymore.
Next click the advanced mode from the drop down next to the column groups as you did before.
Select the two static items in the ROW GROUPS and set the "RepeatOnNewPage" to true.
Finally, for testing, I set the interactive size height property of the report to 10cm (so I could force some page breaks before then end of each group).
After following this, the report worked as expected, below you can see the 2nd page for yellow has the correct header.
In case it's useful, I used Report Builder 2016 to build the sample RDL. You can get hold of it here, you'll just need to edit the connection properties to get it to run.
Link to GroupHeaderRepeat.rdl
https://1drv.ms/u/s!Al1Kq21dFT1ijb5Qmm2P4zyM1MV4pA

Adding values to a Report when there is no Data in query SSRS

I have a query that returns Sales representatives number, Category, Sales.
The result is something like this:
There are 4 categories called G1,G2,G3,G4.
As you can see the Sales representative 11 sold 10 each category (Yellow rows).
But Representative 12 sold only for category G3 and G4.
The idea is to show in the report all the categories and populate with 0 all those who did not sell on that particular category.
It must be grouped by Sales Representative so if you make a tablix grouping by Sales Representatives you will have something like this:
But you want something like this:
Is there any expression I could use to add these?
What I did so far is to create a group, that group of course are my Sales representatives and combine the cells for that Column and created a Row group for each category, is something like this:
But if you execute that report it will repeat all categories G1,G2... For each time that category exists for that particular Sales Representative.
Another problem is, how can you evaluate The hardcoded category in your report if it does not exist in your datasource you cant make Iif("G1" = Fields!Category.Value,Fields!Sales.Value,"0") as you are not comparing G1 with Null or IsNothing, you are comparing what it exists.
I think you can achieve this smoothly using T-SQL at query level. I don't know why you don't use the simplest way to apply this kind of logic since in T-SQL you can use almost every logic.
However I like this kind of challenges so I come with this possible solution.
This is my sample dataset:
In SSRS dataset (not in T-SQL) I've added a calculated field called Another
Another field is set to the below expression:
=Fields!SalesRep.Value & "-" & Fields!Category.Value
I've added a tablix with the following data arrangement
As I mentioned before category field is hardcoded, the right column with Sales
is set to this expression:
=iif(IsNothing(lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7")),0,
lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7"))
Note: ReportItems!Textbox62.Value corresponds to textbox where G1
was hardcoded. You have to replace the textbox reference for the
corresponding in your tablix for every category.
It will preview the below tablix.
Let me know if this was helpful.

SSRS report - add extra table and chart to show occurence of character string in one of the main report's columns

I have an SSRS report based on stored procedure dataset. The report shows employees and their performance rating and uses bunch of parameters to filter the data.
Now I would like to add a table below that would dynamicaly count and show occurence of given mark in the main report. The table data should update according to what is visible in the main report after filtering it.
I wanted also to add a chart that would visualize this.
It would be feasible to do if the extra table and chart could run from the same dataset as the main report. This however seems impossible as this dataset does not always contain all the possible marks. It can happen that some marks are missing (when filtered or missing at all), and I would like to show the mark with zero value (and zero value bar in the chart) instead of just skipping it.
So far I was able to produce the table by hardcoding the headers and using SUM(IIF...) expressions under each header
Here is the expression for the "C" column.
=Sum(IIf(Fields!current_performance_rating.Value = "C", 1, 0))
It shows correctly the number of "C" marks appearing in the main report.
Now I am stuck with creating a chart that would show this.
I am not able to hardcode expressions similar to the ones in the table
and can't make the chart run from the main dataset, because the categories
would be missing after filtering the report (and not showing zero).
I tried linking datasets with Lookup function, but that did not work.
Which way should I go now? What is the best practice in such case?
Thank you for any hints!
Thanks trubs.
I have right joined a view that contains
all the marks and that solves the issue
of missing categories.
The join is on something like
tb.current_performance_rating = vw.performance_rating_code
I can now add the value series that counts
the occurence of current_performance_rating
per category. This works all fine.
However there is another table joined
(on employee_id) that stores last year's rating.
This rating obviously may differ to the current one.
On the same chart I would like to add another
series that counts last year's rating per category.
The category is there already, joined to the current
rating.
So you can have row like:
curren rating | last year's rating | category
C | H | C
So I am stuck, because when SSRS groups per category
it counts last year's H rating and displays
i the C category, while it should display it in H.
Sorry I can't post any pictures, seems like I
need more reputation points.
Hope you can understand what I mean.
Regards!
You're likely better off changing your query to return results for marks where there are no values.
So instead of inner joining to your Performance Rating table, use a Right Join or Full Outer Join, so that all the data is always available.
eg: Instead of...
SELECT p.PersonId, PersonName, g.Grade
FROM Person p
INNER JOIN PersonGrades pg ON p.PersonId = pg.PersonId
INNER JOIN Grades g ON pg.GradeId = pg.GradeId
Use
SELECT p.PersonId, PersonName, g.Grade
FROM Grades g
LEFT JOIN PersonGrades pg ON pg.GradeId = g.GradeId
LEFT JOIN Person p ON p.PersonId = pg.PersonId
If that's not clear, post your query and we could help get the data in the right format.
The way to go was to simplify the dataset that the main report was based on.
Then I took the query from that dataset, used COUNT and GROUB BY to count number of occurence of each current year mark in the main report. Then I right joined (thx trubs!) with the view that contains all the possible marks (so that my extra table headers/chart categories would not disappear if they do not exist). As a result I got the number of occurence in current year per mark (table A).
Then I did almost exactly the same for the last year's rating, just used last year's mark. I got the number of occurence of last year's mark per mark (table B).
I inner joined table A and B on common column (the mark, which will always appear thanks to the RIGHT joins). This gave me a table (dataset eventualy) where I had:
mark | current year mark count | last year mark count.
Making a table and chart basing on this was really easy then.
There was some more fun of adding all the parameters from the main report to both the count queries, so that the counts would change when report is filtered. I also needed to make sure that count works not only when my filter criteria (in WHERE stetement) equal the parameter provided from the report, but also when they are NULLs (so I added OR column_i_filter_on IS NULL).
This works smoothly - the table content and chart changes when filtering changes (although runs slowly, as parameters are passed to two big dataset, one of which uses them twice).
Thanks for all the help!!
psh

Total of unknown categories in SSRS 2005

I am working with SSRS2005. I have requirement to display total in the footer. We have to display the total of each category. What I used to do is, write expression for all category names and hide those totals that are not having any value in the current selection.
Mango Count = sum(iif(fields!Category.Value = “Mango”,0,1))
Apple Count = sum(iif(fields!Category.Value = “Apple”,0,1))
However, in the new requirement, I don’t have the knowledge of categories. It could be any number of categories. Is it possible to write an expression for this?
Please help
Thanks
Lijo Cheeran Joseph
Remove the footer from your table. Create a second dataset that sums by group (Select Fruit, Count(*) AS FruitCount From Fruits Group by Fruit), then add another table below your current table which uses this new dataset and displays the results.