SSRS first function automatically added - reporting-services

I'm using SSRS in SQL Server 2008 with Report Builder 3.0 and was wondering, when I add a field on my report from a dataset, why does it automatically add the First() function to it ?
Instead of adding [Field] in a text box, it adds =First(Fields!Field, "Dataset")

Datasets are assumed to always be multiple rows (even though that may not always be the case). So when you drag a field to a report object that isn't meant for multiple rows - such as a textbox - SSRS needs to use an aggregate function of some sort, so that if multiple rows do come back from the dataset, the report doesn't break (since that textbox isn't made to automatically repeat itself for every row).
FIRST is chosen simply because it's least destructive; it could just as easily be SUM, AVG, or any other aggregate function.

Related

SSRS Create As Many Tables As Needed (Using One Dataset) Based on a DataSet Field

I have a query that returns relevant data about inspectors and how long it takes them to respond to issues. The only parameters are a BeginDate and EndDate so for any given date range there could be anywhere from 0 to 100 inspectors.
I am using only one dataset and it contains an "Inspector" field that I'm hoping can be used as a filter to create as many tables as there are inspectors.
I know you can set filters on tables but from my (limited) SSRS knowledge, you must already have the tables created and the filters are typically hard-coded. What I need, is some way for the report to see how many Inspectors there are in the dataset and group those records into their own tables, repeating the same one created tablix over and over as needed.
This is being done strictly in SSRS 2012, not using a ReportViewer where back-end code could help me out unfortunately...
I don't have any code examples to provide, like I said I know you can do filtering but I am at a loss when it comes to doing something like this dynamically based on data... Sorry.
Depending on the report design you could either...
Single report with grouping
1. Create a single tablix.
2. Create a row group by Inspector and then add whatever fields you need to the details section.
3. You can optionally set page breaks between instances of your Inspector rowgroup from the rowgroup properties.
Sub report method
1. Create a subreport that accepts a parameter (InspectorID for example).
2. In the subreport filter the dataset using the parameter passed in so it only return data for a single inspector.
3. Add whatever controls you need to the report to handle a single Inspector
4. Create a main report
5. Add a dataset that gives you a simple distinct list of Inspectors, this will be used to pass parameters to the subreport.
Lets assume it just contains a list of InspectorIDs.
6. Add a list control to the report and set it's dataset property to the dataset that contains your list of InspectorIDs
7. Right-click in the list control's 'cell' and insert a subreport.
8. Set the subreport property to the subreport you created earlier and set that parmameter IsnpectorID to your InpsectorID field.
This will produce a subreport for each instance of inspector it finds.
Sorry about the format of this answer, in a rush!

Access - Modular reusable subreport

I would like to create a report which I can use as a sub-report multiple times on the same parent report. However, each occurrence of the subreport should have different values.
For instance, there is a table called DailyReport.
Records in this table contain:
Date, member, team, description
The sub reports should be for each team within a certain date range. However, the date range per subreport/team will not be the same.
So, if the date range for all teams was consistent, then I could create a single subreport, and do some Ordering on the resulting records to separate things out into teams.
However, with inconsistent date ranges, I can't utilize a single query, so the most straight forward solution I see is to create separate subreports and queries for each range of each team.
The problem with this solution is that if I decide to change the format of the subreports I must do so in each specific subreport--a lot of duplicate work.
I would like to create a generic query and subreport. The query and sub report would call VB functions which would return the relevant value.
This means my parent report has the same generic report on it multiple times. As each subreport is rendered, I would like to increment a value behind the scenes so that the functions which the generic query and subreport call know to return a different value.
However, it seems that's not how things work in Access. The subreports on a report are not rendered linearly. A subreport is created, and then "stamped" onto a report where ever required. This means that all of my generic subreports have the same data.
How can I define a generic report and query? Then plug in different values into the report and query while the report is being reused multiple times on the same parent report.
You need to look into the LinkMasterFields and LinkChildFields property of reports. They are designed for exactly this purpose -- to filter a subreport based on current data in the main report, without needing any code or even queries.
You are correct that LMF/LCF do not work on date ranges, only values. So use LMF/LCF for the team filter.
For the date range filtering, you can use an unbound form that launches the report as two parameters defined in the base query. Create frmLaunch, and add two text boxes minDate and maxDate. Set their Format property to Short Date so Access with interpret them correctly and provide the date pickers. Now modify the base query, adding two Date/Time parameters [Forms]![frmLaunch]![minDate] and [Forms]![frmLaunch]![maxDate]. Now, find your date field and set its criterion to Between [Forms]![frmLaunch]![minDate] and [Forms]![frmLaunch]![maxDate]. Add a button to frmLaunch that runs the code DoCmd.OpenReport "YourReportName", acViewPreview.
So, the goal was to make it possible to re-use the same sub-report multiple times on the same parent report, with full flexibility on how the subreport retrieves data.
I placed multiple instances of the same subreport on a parent report. On the subreports Open event I placed a line like
Me.Report.RecordSource = "SELECT * FROM someTable WHERE " & getCriteria()
nextCriteria()
Maybe its possible to pass a value that identifies which instance of the subreport is opening to the getCriteria function. Probably like a getCriteria(Me.Report.Name). But in this case I kept track of how many subreports had been produced in vb.
Unfortunately, if your subreport has controls which have a data source which is a vb function, all reports will show the same value for that control. To get around this I added something like getSomeValue() & "As [Some Value]" into the SELECT of the SQL statement above. Don't forget to add single quotes or hashes around getSomeValue() if you are passing a String or date.
That's basically it, it's a pain. But I couldn't find a more elegant way to do it.
Edit:
One major caveat I experience with doing this, is that although the print preview works correctly, when actually printing or exporting to PDF, some subreports would not be included. Maybe there is something else causing this...

SSRS 2005 Syntax for using two datasets in one expression

I have the following expression that works beautifully to add two values, regular hours and overtime hours.
Sum(IIF(Fields!BillStatus.Value = "F", (CDec(Fields!RegHrs.Value) + CDec(Fields!OvtHrs.Value)),CDec(0)),"ReportDataset")
What I need to do is add a third value to that, but this third value will come from a different dataset, and I cannot seem to find the proper syntax for that.
Somehow, immediately after the OvtHrs.Value, I need to say something to the effect of...
+ (Fields!HoursWorked.Value, "RBaseJobBaseline")
How do I inject that value as part of the "true" clause of the IIF, since it needs to come from a different dataset.
The only way to combine sets in SSRS it's
Lookup [msdn][1]
LookupSet msdn
MultiLookup msdn
But these functions comes to SSRS from MS SQL 2008R2 version, unfortunately in SSRS 2005 you can't do this and you should combine datasets only in data base level.
[1]: http://technet.microsoft.com/en-us/library/ee210531.aspx ????
Combine your datasets (or SQL queries) into one query.
Use the DATASETS option in SSRS2005 (via Properties of your control) to capture the "root" or main dataset by using the report aggregate functions such as FIRST(), SUM(), etc.
To report the detail of your single dataset, use the FIELDS option.
SSRS2005 can only work on ONE dataset at a time, unless you use multiple tables (or lookup parameters, etc) with different datasets, but they are still totally independant of each other.

SSRS IIF Syntax with Multiple Datasets

I have a report with 2 data sets and would like to perform a SUM operation in a textbox expression. The problem arises when I want to perform an IIF in the sum since I only want a particular category of values summed.
I would like to get a sum of all the "Good" ranking values from the dsRetrieveCustomerAssetScores dataset. Please note there is more than one data set in the report, so I need to specify the scope when using the aggregate function. Below is the code I've tried (along with other permutations).
=Sum(iif(Fields!ranking.Value,"Good",1,0), "dsRetrieveCustomerAssetScores")
Any ideas?
You may have more than one dataset in your report, but I don't think it's possible to have more than one dataset per tablix. (Subreports within the tablix may be bound to a different dataset, but anywhere within the subreport will only be accessing that other dataset.)
The scope specified within aggregation formulas is normally related to groups within the tablix, not the datasources.
So, the code:
=Sum(iif(Fields!ranking.Value,"Good",1,0))
- should work within your tablix, as long as that tablix is accessing the dsRetrieveCustomerAssetScores dataset.

Sql Server 2008 Reporting Services: Using two dataset error

Im building a report that's using two datasets. when I preview I find these types of errors...
Error 19 [rsFieldReferenceAmbiguous] The Value expression for the text box ‘Textbox3’ refers directly to the field ‘PerZipCode’ without specifying a dataset aggregate. When the report contains multiple datasets, field references outside of a data region must be contained within aggregate functions which specify a dataset scope.
What aggregate function is needed and where is there an option to set this?
If you are adding multiple datasets to a report, the above may not fix your problem. You may just get the following error when you aggregate it:
[rsMissingAggregateScope] The Value expression for the text box ‘textbox6’ uses an aggregate expression without a scope. A scope is required for all aggregates used outside of a data region unless the report contains exactly one dataset.
What you may need is something like :
First(Fields!MyField.Value, "DATASETNAME")
Which you can get by using the Expression Builder, rather than the drag and drop of fields from the dataset.
Min or Max or Avg etc: most of these
The aggregate is needed to reduce the other DataSet to one value (max of values etc) because you are using something not in the local scope (eg the DataSet bound to the Data Region). There is no way to match rows in the other DataSet with the local scope DataSet.
If your text box is standalone (not in a Data region), the same applies: the aggregate is needed to tell SSRS which row to take (Max etc) or what calculation to do on the dataset (Avg etc)
To use multiple dataset value on SSRS report we need to use below code.
First(Fields!MyField.Value, "Datasetname").
If by typing this you are still getting the same problem then right click on textbox & select expressions then in expressions click on Dataset. Select you dataset & then double click on required column. After this click on ok.
If you have multiple controls then follow the same for all of them & verify the same by executing the report.
If you already have an aggregate and are having this error, it is probably because the fields of the report aren't up to date with the dataset(s). You can fix the issue by refreshing the fields of the report.
To populate the field collection, use the Refresh Fields button on the Dataset Properties dialog box.
The field collection does not appear in the Report Data pane until the Dataset Properties dialog box closes.
To refresh the fields for a specific dataset
In the Report Data pane, right-click the dataset, and then click Dataset Properties.
Note :
If the Report Data pane is not visible, on the View menu, click Report Data. If the pane opens as a floating window, you can dock it. For more information, see How to: Dock the Report Data Pane.
In the Query pane, type the query. Alternatively, you can use the Import button to import your query from another .rdl file.
Click Refresh Fields.
Click OK.
In the Report Data pane, expand the dataset node to view the currently defined field collection.