passing array values to a subreport - crystal-reports-2010

I am new to crystal report and I need a help.
I have a report having two groups,project id and work_item. And I placed 3 sub reports material,labor and equipment reports in the work item group. They pass a value to the main report that is used for further calculation which is specific for a work item..
Since it's a work item specific,I placed the final result in the work item group footer.
I placed another sub report called bill of quantities in the work item group footer that needs the final value. It's also work item specific The value being passed is fine but I am having issues with the format.
After displaying the detail of one work item,the sub reports detail follows it which I didn't want that to be displayed. I tried placing the sub report in the project id group footer. The format I need is good but the value being passed is the same for all work items in the sub report.
The thing I need is after displaying all the details of the main report then displays the sub report detail.
Is there a way to store those final values of the work items in an array and pass them to the sub report.

Well, Yes you can store details in an array, when you are loading the main report, loop thorugh the data of the main report :
shared stringvar array items;
for int i:=1 to limit(count of project_id)
do
(
whileprintingrecords;
items[i]:= //add values, you can make a logic, this is just the demo
);
items;
Then simply place this formula in a section suppressed, just above the subreport, so that this can be passed with values in the subreport.
Declare a formula, and use the shared values:
shared stringvar array items;
numbervar count_i:=//get the count of items and add array values into another formula/field.
//place that field in subreport, this may require some brainstorming from your end, but this is the way in general.

Related

SSRS Static fields in groups

Good afternoon!
I have created a report with the wizard to create a matrix that is grouped and has drill down rows. I have added filters to the rows and columns and it works great! I then copied that matrix and modified the filters, so I had two matrixes.
But what I really wanted was those two rows in the same matrix, just in different row groups. So I added another group, using the adjacent below option, and then added all the child groupings. However, when I run the report it shows the values for the first row of the drill down data.
When I look at the groupings I can see the one I did manually has a 'Static' field in each row grouping but the ones that the wizard did (with the red ?), they don't have that "extra" row:
What do I need to change or how do I need to add my groups so that I don't get that "static" row and not show the data? I have the visibility set to 'Hidden' and the toggle set up for the prior grouping set data.
Assuming a few things....
the data comes from a single dataset
You are differentiating between Property and Violent crimes by filtering on a column, I'll call it IncidentGroup for the sake of illustration..
I've understood your question ! :)
Get to the point where you had just a single tablix filtered to show 'Property crime'.
Now remove or edit that filter so it shows all the data you need in the report.
Finally, right click on your Matrix1_IncidentCategory row and add a parent group, choose IncidentGroup (or whatever the column is actually called) and check the box to add a group header.
That should be it, there is no need for a second tablix.
Without knowing how you are filtering currently it's hard to give a complete answer but this should get you close, if not all the way there.
If this doesn't work for whatever reason, please post sample data from your dataset output and your current filters.

Can I use a list to repeat two tablixes on a report page?

See image below. Warehouse and Customer are dropdown lists populated via query. Year is a text field. The two tables display data from datasets driven by the report parameters. Is there a way to repeat the two tables based on each member of the Customer dropdown? Preferbly with a pagebreak after the 2nd table.
I normally do this using subreports. You could either create a single subreport that contains both tables or individual subreports. The individual approach might help with page breaks etc so that's the way I'd go.
Step 1: Create a report for your first table.
As you don't state what each table does, I'll make some up for the sake of illustration.
The key is to create a subreport that displays just the info you need in a single table. So in your case this might mean we only need to pass in a single parameter, CustomerID. You might need to pass in more such as Warehouse but I don't know...
In my made up scenario, let's assume the report shows customer contacts so we create a subreport (let's call it subCustomerConacts). It has a single parameter pCustomerID and a single dataset dsCustomerContacts. The query might looks something like SELECT * FROM CustomerContacts WHERE CustomerID = #pCustomerID. Add whatever tables/textbox etc you need to display your data.
Test this subreport works by manually typing in a CustomerID
Step 2: Create a report for your second table.
Do exactly the same again, creating a new subreport. Let call this subCustomerOrders. Repeat as above until you end up with another report that can display order details (or whatever you need).
Finally, create you main report.
This is basically what you have described in you question in terms of parameters etc.
Now to add this bit that will call you subreports.
Create a dataset (let's call it dsCustomerLoop) that contains each customer from your parameter something like SELECT DISTINCT CustomerID FROM myCustomers WHERE CustomerID IN (#myCustomerParameter)
Add a table to your report, 1 column wide and stretch it so it's wide enough to accommodate you subreports.
Set the dataset to point to dsCustomerLoop
Right-Click the cell in the detail row and do "Insert Row -> Inside Group - Below". You should not have two detail rows.
Next, right click the top detail row and do "Insert -> Subreport"
Right-Click the newly inserted subreport control and choose "properties".
Choose your first SubReport form the drop-down list
Click parameters on the left,
Click "Add" and select the CusomterID parmeter, set it's value to the CustomerID field.
Repeat this process on the seconds row, choosing your seconds subreport.
You may want to also add a 3rd row to the table, you could insert a rectangle into this with page breaks set to force a new page after each seconds subreport.
That's It. When the report runs it will produce two rows per customer, each row containing a subreport.
I hope this is clear enough, I've rushed through it a bit but if anything is unclear, let me know and I'll provide a clearer solution.

Crystal Reports Setting Global Subreport Variable

I am trying to set a couple of global variables in a subreport so that it pulls and stores the data I need in each.
Say I go into the formula workshop and create a new formula. Right now I have
Global numbervar name:= ;
I have a single table with multiple fields. I have one field named {table.order} and another named {table.amount}. Both of these are numbers. How do I assign to this variable the amount in the associated amount field when the order is -1? I'm really not familiar with crystal syntax at all.
After this, where would I need to drag and drop this formula in the report to pick up this data or is simply creating the formula in the formula explorer enough? If it needs to be physically dragged into the report, will anything show up or will I need to suppress it so it is not visible and if that is the case, will it still work suppressed?
Thanks for any help you can give.
Are you trying to pass the value in this variable back to the main report? If so, you'll need to make this a Shared Numbervar, not a Global Numbervar.
To answer your question; create this formula:
global numbervar name;
if {table.order} = -1 then name := {table.amount}
...and drop it into your subreport's details section. Note that any formulas, summaries, running totals, SQL expressions, etc. that you create but are not placed in the actual report won't be run. However, after placing it in the report, it will display. To prevent this, right click on the field, go to the 'Common' tab, and then check 'Suppress'. The formula will still work when suppressed.
One other thing to keep in mind is that if your subreport(s) contain more than one row of data, the variable will be overwritten for each.

SSRS Detail members can only contain static inner members

I am developing an RDL in SSRS 2008 and am trying to move a subreport table directly into a main report so that I instead run this subreport in the same stored proc as my main report.
However, I'm having trouble hooking this up. I got the stored procedure to run successfully. But now when I try to copy this table into the main report I get the following error:
[rsInvalidDetailDataGrouping] The tablix 'table1' has a detail member with inner members. Detail members can only contain static inner members.
Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope
How can I do this?
I have tried moving the table into the group level and deleting the details grouping. I have removed sorting elements, etc. But the only way I got this error to disappear is to delete all of the groupings for this table and all textbox values.
If these are being returned from the same SP, then you should only have one Detail group (and one tablix).
The detail group (on your outer tablix) will be repeated once for each row returned by your dataset. A tablix contained within that row for the same dataset doesn't make sense: what would it repeat?
It sounds like you need to combine your two tablixes into one, not nest one in the other.
The easiest approach is probably to add a group to the parent tablix which will take the place of the former detail group. It will probably group by whatever field you joined to your old subreport dataset (or something similar.)
Then put your old subreport fields in the detail rows.
I was getting this error when building a report in VS2015 SSRS14.
A restart of Visual studio cleared the error.
In my case, a simple table report, Tablix4 was giving an error. This is because Tablix1 had a Rectangle as a child, and the Rectangle had Tablix4 as a child. Replacing Tablix1 with Tablix4 solved the problem.
<Tablix Name="Tablix1">
<TablixBody>
<TablixColumns>
<TablixColumn>
<Width>16.51cm</Width>
</TablixColumn>
</TablixColumns>
<TablixRows>
<TablixRow>
<Height>2.38745cm</Height>
<TablixCells>
<TablixCell>
<CellContents>
<Rectangle Name="Rectangle1">
<ReportItems>
<Tablix Name="Tablix4">

Aggregate child table values in Birt

I have this Birt report that I inherited from another developer, consisting of a child table inside a master table. For each row in the master table, the child table lists items belonging to the current master row item.
The two tables are fed from different data sets, the child table dataset taking a parameter indicating the master item whose child items to fetch.
Now, what I need to do is add a SUM aggregate to the bottom of the master table, showing the total (for all master items) of a certain field in the child table.
Consider, for example, the following data:
MasterItem1
ChildItem1 SomeValue
ChildItem2 SomeValue
ChildItem3 SomeValue
MasterItem2
ChildItem1 SomeValue
ChildItem2 SomeValue
ChildItem3 SomeValue
--------------------------------
Total
(Why wasn't this done with grouping instead? Short answer: There are in fact two child tables to each master row, containing different numers and types of fields, so the previous developer probably didn't figure out a way to accomplish this with grouping.)
At first I thought I could simply add another child table inside the Total field, with an aggregate summing up the values from the child dataset. That didn't work, however, since the child dataset requires a parameter indicating the master item whose children to fetch, so there is no way to get ALL values from the child dataset at once.
I'm thinking there might be a way to create an expression that references the SomeValue fields in the child table directly, instead of going through the child data set.
Any suggestions are greatly appreciated.
It should be possible to declare a global variable at the start of the report, then add each of the child values to it in one of the child table row events and output it at the end of the reports - if you're comfortable writing Javascript, this is probably the quickest solution.
If you're not comfortable writing Javascript (I'm not) or if the above technique doesn't work out, you could try either:
creating a third dataset, combining the master data items from the main report with the child data items from the subreport and outputting the total in a new data table, or
combining the two existing child data value tables via a union (so that if the master table is A, the main child table is B and the subreport table is C, you have AB union AC), replacing the subreport table and the existing detail rows with new detail rows conditional on child row type, and a total at the end of the report based on the AC values.
Obviously, the latter of these approaches is more complicated - but I think it should be easier to understand and maintain.
The Global Variable is the way to go. For each row in the child table, add the required value to the global variable and then access it for display at the bottom of the table. There is not any hard JavaScript:
var Sum = reportContext.getPersistentGlobalVariable( "RunningAggregate" );
Sum = Sum + row["column Name"];
reportContext.setPersistentGlobalVariable( "RunningAggregate", Sum );
You can then access the Global Variable in the footer of your table via a Dynamic Text item.
Good Luck!
Thanks Mark and Mystik, both your answers led me on the right path!
My final solution is as follows:
1) Declare the sum-variable in the initialize method for the report:
var total = 0;
2) Add each row's value to the sum-variable in the onReder method of the data field containing the values:
total += parseInt(this.getValue());
3) Use the sum-variable as expression in the total-field.
Works like a charm.
Update:
Found a bug in my solution: the last line was left out of the sum. I think the value of the total-cell in the table footer is being defined before the last line has been rendered.
Fix:
Moved summing code from onRender method to onCreate
Added the following code to the total-cell's onRender method:
this.setDisplayValue(total);

Resources