SSRS IIF Issue expression [duplicate] - reporting-services

I need a row value in my SSRS report that is a calculated one based on a couple of fields that are already being used in the report. I want it to display in the textbox named 'textboxPercentageValue'. In semi-plain English, the expression/formula is:
If the value of the "Week" field is "WK1", display the value of the Variance field divided by the value of the Price field; otherwise, just display the value from the Variance field.
In VB script gobbledygook, the expression/formula I've add to textboxPercentageValue's Value propert is:
=IIF((Fields!Week.Value="WK1"), Fields!Variance.Value / Fields!Price.Value, Fields!Variance.Value)
Yet, when I try to upload the .rdl file to SQL Server Reporting Services, I get:
"The Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Week’ 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. (rsFieldReferenceAmbiguous) Get Online HelpThe Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Variance’ 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. (rsFieldReferenceAmbiguous) Get Online Help
The Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Price’ 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. (rsFieldReferenceAmbiguous) Get Online Help
The Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Variance’ 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. (rsFieldReferenceAmbiguous)"
So what do I need to do to make this expression/formula unambiguous to SQL Server Reporting Services or the VBScript parser or "whoever" is complaining about it?

It sounds like your Textbox has been added to an area of the report that isn't a "data region" (e.g. a table or list). A data region will have a reference to a particular report dataset as one of it's properties, so Reporting Services knows all field references inside that data region refer to that dataset. What this error is trying to say (in a rather verbose way) is:
if you reference a field outside of a data region, that reference needs to be inside an aggregate expression such as Sum() - this is because the dataset may contain multiple rows for the field but outside of a data region a textbox can only display a single value.
this aggregate expression must also include a reference to the report dataset that the field is coming from
So if field "WK1" was from dataset "MyDataset1", the expression to reference that field would look like:
=Sum(Fields!WK1, "MyDataset1")
See also: Using Dataset Fields Collection References in Expressions

This is an interesting problem, because if you have ONLY 1 data set in your report, you don't need a table, you can directly reference a field that exists in that table.
However, if you have more than 1 data set then you must create a table, which may give you multiple rows. Then you might have to group by this one field, and hide the extra columns and rows. However, you CANNOT display this data in a TEXTBOX, you can however create a rectangle which can hold the table and another textbox. Or display the table directly.

A text box can get knocked out of its context and still appear to be in it. I came by this post looking for the same error message and it was one textbox in a series of several and it had worked just moments before I had readjusted formatting. After getting the info in the first answer, I went back and poked around and found the textbox throwing the error was actually be the list box but appeared to be on the same levels as the others unless I was trying to move or resize the list box. Moving the textbox out and dropping it back in fixed things. As someone coming upto speed on SSRS from a programmer prospective, the insight in the first answer solved a frustration that has come up repeatedly!

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!

SSRS has a hidded group statement that is not in the dataset query. How to find it?

REPORT BUILDER 3.0
I am changing the data sets of our reports to standard data sets. In some cases the names of fields have changed. Despite changing the cells to the new names I get an error of:
"The Group expression for the grouping ‘companyname’ refers to the field ‘companyname’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope. Letters in the names of fields must use the correct case.
"companyname" changed to CompanyName and there is no group by companyname in the Dataset SQL. How can I change that in SSRS?
Whenever I've faced this, the places to check are:
Row Groups
Column Groups
Header text boxes for interactive sorting
9 times out of 10 when I can't find it, it's in the interactive sorting on text boxes.

How can I "specify a dataset aggregate" in this SSRS Expression?

I need a row value in my SSRS report that is a calculated one based on a couple of fields that are already being used in the report. I want it to display in the textbox named 'textboxPercentageValue'. In semi-plain English, the expression/formula is:
If the value of the "Week" field is "WK1", display the value of the Variance field divided by the value of the Price field; otherwise, just display the value from the Variance field.
In VB script gobbledygook, the expression/formula I've add to textboxPercentageValue's Value propert is:
=IIF((Fields!Week.Value="WK1"), Fields!Variance.Value / Fields!Price.Value, Fields!Variance.Value)
Yet, when I try to upload the .rdl file to SQL Server Reporting Services, I get:
"The Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Week’ 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. (rsFieldReferenceAmbiguous) Get Online HelpThe Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Variance’ 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. (rsFieldReferenceAmbiguous) Get Online Help
The Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Price’ 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. (rsFieldReferenceAmbiguous) Get Online Help
The Value expression for the text box ‘textboxPercentageValue’ refers directly to the field ‘Variance’ 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. (rsFieldReferenceAmbiguous)"
So what do I need to do to make this expression/formula unambiguous to SQL Server Reporting Services or the VBScript parser or "whoever" is complaining about it?
It sounds like your Textbox has been added to an area of the report that isn't a "data region" (e.g. a table or list). A data region will have a reference to a particular report dataset as one of it's properties, so Reporting Services knows all field references inside that data region refer to that dataset. What this error is trying to say (in a rather verbose way) is:
if you reference a field outside of a data region, that reference needs to be inside an aggregate expression such as Sum() - this is because the dataset may contain multiple rows for the field but outside of a data region a textbox can only display a single value.
this aggregate expression must also include a reference to the report dataset that the field is coming from
So if field "WK1" was from dataset "MyDataset1", the expression to reference that field would look like:
=Sum(Fields!WK1, "MyDataset1")
See also: Using Dataset Fields Collection References in Expressions
This is an interesting problem, because if you have ONLY 1 data set in your report, you don't need a table, you can directly reference a field that exists in that table.
However, if you have more than 1 data set then you must create a table, which may give you multiple rows. Then you might have to group by this one field, and hide the extra columns and rows. However, you CANNOT display this data in a TEXTBOX, you can however create a rectangle which can hold the table and another textbox. Or display the table directly.
A text box can get knocked out of its context and still appear to be in it. I came by this post looking for the same error message and it was one textbox in a series of several and it had worked just moments before I had readjusted formatting. After getting the info in the first answer, I went back and poked around and found the textbox throwing the error was actually be the list box but appeared to be on the same levels as the others unless I was trying to move or resize the list box. Moving the textbox out and dropping it back in fixed things. As someone coming upto speed on SSRS from a programmer prospective, the insight in the first answer solved a frustration that has come up repeatedly!

SSRS dynamic data retrieval from another dataset

I want to get data(dynamic) according to the data in another dataset and put the result in textbox of the different dataset.
Right now, the data I get is static and I tried to use many expressions but no avail.
Problem lies in editing textbox expression. Since I am getting data from different dataset, it always ask me to have dataset aggregate function in my expression. If I specified the dataset from where I am getting the data, then, I cannot make it dynamic - and I get the undesired result.
And another way out that I attempted is merging the data sets into one rather than having multiples and use it only but this was unsuccessful.
How can I make it work to get the result that I want:
By the way, the textbox and the tables are in different scope. I have tried to combine them in one scope too.
Getting data from another dataset requires an aggregate function because it can't tell what data you want from that dataset so it forces you to aggregate it so it can return a specific value rather than an entire list of values.
I think what you are after is the Lookup function. Lookup allows you to look up a value from another dataset based on a value in the table's dataset. To give a simplistic example, let's say your table was of employees and you had a department id on that table and another dataset called "Departments" which had an id and a name. You could look up the department's name using the following expression:
=Lookup(Fields!DeptId.Value, Fields!Id.Value, Fields!Name.Value, "Departments")
This uses the current table's dataset's DeptId field to look up the Departments dataset by the Id field and return the Name field.
=Lookup(First(ReportItems!EmpID.Value),Fields!EmpID.Value,Fields!Dept.Value,"dataset_which_u_retrieve_the_data_from")
Problem solved!By using reportItems instead of Fields because I am retrieving one data only,not the whole field.
Thanks guys for helping me out.

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...