SSRS: Dynamically Creating New Matrix - sql-server

I have the following format in my dataset (see Dataset Layout screenshot).
I need this report to show like the following (see Report Layout screenshot) with a bit of a difference, but first let me explain.
This report is a "monthly" report that shows the data for each day of a given month. What I have shown in the Report Layout screen shot is how the report displays if the user only selects one available value for column "Level!2!Sample". So in other words, instead of seeing multiple values in that column as shown in the screen print, it would only contain one distinct value. This report works when only one item is available, but I need to allow for multiple options.
What I need to do is be able to display data like this for multiple values of "Level!2!Sample", and each time a new "Level!2!Sample" is encountered, it would create a new matrix as shown in the screen print. So if there are four distinct items for this column, I would have four different tables shown on the report, each displaying the data for the given distinct value of the "Level!2!Sample" column.
I assume I would need to use an "Order By" clause to get my data looking correctly:
Order By
Level!2!Sample,
name!3!Title,
month!4!ReportMonth
But I am not sure how to get SSRS to create a new matrix when the new level!2!sample record is encountered.
I hope my explanation makes sense as to what I am trying to do. Any help is greatly appreciated.

You can't create a new matrix like that but there are other options.
Simple option: Create one big matrix grouped by Level!2!Sample and have page break between groups. This would obviously mean you would end up with 4 pages in your sample scenario which may not be ideal.
Slightly less simple option:
Create a new report
Include your parameter as you did for the current report.
Add a dataset (let's call it dsLoop) that returns a single column and 1 record per selected parameter entry. This might look something like SELECT DISTINCT Level!2!Sample FROM myTable WHERE Level!2!Sample IN(#myParameter).
Add a table with a single column and a single row and set it's width to the width of your report/page.
Set the dataset for the table to be dsLoop
In the table's cell insert a subreport and set the subreport properties to point to your original report
Set the subreport parameter to Level!2!Sample from your dataset.
Notes:
a. You can get rid of the available values and related datasets from your original report as these are no longer needed (optional)
b. You can add rows before or after the cell with the subreport if you want to add gaps between each tablix.
Basically your new report acts as a loop and creates one row per selected item in the parameter list, each row contains an entire subreport with the parameter for the current row passed to it.
The net result is that you will get a 'new' table for each selected entry.
Hope that makes sense.

Related

SSRS Report Builder Sub-Report Sorting

I have an SSRS report that contains 20 sub reports in it. Each sub-report represents a phase in a specific cycle. All sub-reports are identical in formatting and such, containing specific data to that phase and displaying a start and end date. I was wondering if there is a way in Report Builder to essentially have those sub-reports be dynamic and sort themselves based on their specific start dates instead of just displaying them the one I have them listed in my report?
This is quite simple.
You already have you main report and sub reports so that's good. I assume your subreport takes a parameter which indicates the phase.
Assuming this, let's say the parameter your sub-report accepts is called pPhase
In your main report, remove all the existing sub reports
Next, create a dataset, lets call it dsLoop
Set dsLoops dataset query to return the phases in order for example SELECT DISTINCT PhaseNumber from myTable ORDER BY PhaseNumber
Now add a table control, remove the header row and two of the columns leaving just a single cell.
Make this cell as wide as you need, wide enough for your subreport, height does not matter.
Set the DataSetName property of the table to dsLoop
In the remaining cell, right-click and choose Insert --> Subreport. A subreport control will fill the cell.
Right-Click the subreport control and choose Subreport Properties, choose your subreport from the list
Still in the subreport properties, click the parameters tab, add a new parameter.
Set the Name to the parameter name that your subreport accepts (pPhase in our
example) . Finally, set the Value to the name of the field that contains
your parameter data (PhaseNumber in our example)
That's it...
Now when you main report runs, a row will be created in your table for each entry in dsLoop, each row will contain your subreport and each will have the parameter passed to it that is specific to each row.
If you have any issues, let me know and I'll post a full example.

SSRS Selective Page Break

I'm having some formatting issues in SSRS with a current report I'm working on concerning property records. My report is built with 6 tablixes aligned in a landscape view meant to remain in a specific layout for potential printing of the report.
The first Tablix contains general information about the property in question and the owner. This information will be completely static and should remain the same.
The second Tablix is the problem. This Tablix is formatted to pull data from a stored procedure concerning parcels of land and generate up to 13 rows, filling in NULL values if less than 13 rows of data exist. The issue is if MORE than 13 rows of data exist. Currently, the result I have stretches the report and messes up the formatting entirely with 14 or more rows.
There are 4 other tablixes below this Tablix that contain additional details about the property, including buildings, outbuildings, and general appraisal summaries for the property. These will remain the same, as well. Each of these tablixes pulls from its own data set and has a stored procedure to generate the rows as needed.
My goal is to generate a report that contains up to 13 rows of land data on the first page and with any additional rows, keep the same exact page layout, but with the land data Tablix filled with rows 14-26 on a second page. That is, the layout from the first page of the report is repeated but with the remaining rows of data within the land data Tablix.
I've included the layout of the form for reference and I'm currently using Report Builder 2012 with MSSQL. The Land Section Detail is the Tablix in question.
Report View
Honestly, I'm not sure that this is possible, but I'm open to any suggestions on how to make this work.
EDIT: Changed the picture to provide a better idea of what I have.
EDIT: Adding "Sample Data"
Also a Link
Best sample I can offer considering the size of the data set
I once had the same problem to limit the row numbers of a tablix. This description was the solution:
Display a fixed number of rows
I was able to solve this issue with a somewhat complex method, but a method that worked perfectly for the report. The basic idea was to use a temporary table to keep all of the data aligned with a row count and page number in each dataset. With that row count, I was able to determine a cut-off point for each page. For example, if a Tablix had room for 9 rows of data, each of the first 9 rows of data were assigned the page number 1. Rows 10-18 would be assigned page number 2. In this way, I was able to group the report based on the page number.
If no data was assigned to a given page, I had an additional dataset that generated the correct number of blank rows to fill the same gap and maintain the correct page layout.

SSRS Error - "Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate

I'm new to SSRS and I'm not sure if it will do what I would like to do.
I'm getting the following error in SSRS:
"The Value expression for the text box 'Textbox17' refers to the field 'DayCnt'. Report item expressions can only refer to fields withing the current dataset scope or, if inside an aggregate, the specified dataset scope. Letters in the names of fields must use the correct case."
I have a list that's 3 rows and 3 columns. I need to use multiple data sets across the rows and columns. I would like everything on the report to be grouped on the school ID, which each dataset does have.
I will be using multiple datasets per cell in some cases and I'm using a textbox and then dragging the dataset field into it. I'm not sure if grouping is the problem. I'm not sure how to group the entire list at once, or if it is row based, or how the grouping works with a list with multiple columns.
How can I get everything in the list to be based off of the school ID?
You can reference more than one dataset in the same data region (table, etc.) but only if it makes sense to use aggregate functions on all the datasets except the primary one that your grouping is based on. I'm not sure if this makes sense for your use case or not.
An aggregate function is something like First. If you don't specify the dataset, it defaults to the "current dataset." The current dataset is an invisible default that you can't see or set anywhere in the UI, as far as I can tell.
=First(Fields!MyField.Value)
vs.
=First(Fields!MyField.Value, "MyDataset")
Now, there are a couple of tricky things to know about the Report Builder UI.
When you drag a field into your report, the expression it creates does not specify the dataset.
When you drag a field into your report, it changes the current dataset!
This leads to exasperating behavior such as the following:
Create a data region.
Set its grouping to a field from Dataset1.
Drag in a field from Dataset1.
Run the report. It works!
Drag in a field from Dataset2. RB will automatically use an aggregate function, as you would expect.
Run the report again. Now you get an error, not on either of your fields, but on the grouping of your data region.
The problem is that dragging in the field from Dataset2 changed the current dataset to Dataset2 and broke everything that uses Dataset1 without explicitly specifying it. The solution is hacky:
Manually change the expressions of all your fields from Dataset2 so they explicitly reference the dataset, or
Reset the current dataset by dragging in a field from Dataset1 and deleting it.
You cannot use different datasets on only one SSRS table. One table should only refer to one dataset.
And the solution to your question is: recreate your dataset (query), try to get one dataset by using distributed query if they are on different server instance, or specify database name when they are on the same server.
You might have done some modification on the Dataset and you did not refreshed the fields.

SSRS - How to fit the content of a table into a single page for each table and not have part of the table spread between 2 pages

I have the following table (see the table below). It is querying into a table in my database, which has around 10 000 lines.
It starts well as you can (also below)
Issue is when going to the second page and after, the table is spreading around.
updated version after my wrong description: What I want actually is to have several tables in one page , with the last table complete with the 8 rows at the end of the page and have the next table start on another page.
I tried to set the tablix and the rectangle ,with the following properties:
General
KeepTogether = True
PageBreak
BreakLocation = End
Disabled = False
ResetPageNumber = False
However, it is still not giving me the desired results.
Any tips are more than welcomed
Put your table inside a List Item, and deactivate the Add a page break after in the List.
Or if you want to fit as many tables as possible on a page, but keep the page break from splitting them, here is how I have done this in the past:
Create a sub-report that contains a single tablix for a single data entry.
Put a single-celled tablix on your main report that gets the list of data entries for the full report.
Put a rectangle inside the single cell.
Put the sub-report inside the rectangle, and pass it the ID of the data entry.

SSRS 2005 unwanted page breaks between subreports

I have a report that has one table with two rows. The first row is just a header, the second is a subreport. The subreport consists of a single table. I want to pass one parameter into the subreport (Fields!patient_id.Value) and have the subreport repeat for every patient id. I have that working, but for some reason it inserts a pagebreak after every instance of the subreport when I look at the print preview, even though it could easily fit four of them on one page. I haven't set anything to insert a pagebreak at any place in the report or the subreport. I do want the page to break, but only when there is not enough room on the page to fit an entire subreport.
I've done enough troubleshooting to be able to say for certain that it is the subreport control or the subreport itself that is causing the problem, not the table. Any help would be appreciated.
Edit: It's also important to note that when I preview my subreport, there are no page breaks.
I found a solution. Instead of putting the subreport into the table, I put it into a list with a grouping expression of "=Fields!patient_id.Value".
set the ConsumeContainerWhitespace = True on the Report Properties
default is set to false and it attempts to preserve the blank space next to your table

Resources