SSRS Recursive Hierarchy for Bill of Material - ssrs-2008

I am trying to create an SSRS report for a Bill of Materials (product structure) with parent child recursive grouping to enable drill down to multiple levels.
I have achieved the goal of doing this with a recursive CTE and including a parent recursive reference to the Child group in SSRS.
This produces a very pretty report that allows for drill down to levels with indents and levels and everything! Just one problem.....
By grouping on the Component to get the recursive technology to work, the result set of my CTE which has 37 rows gets truncated down to 32 due to multiple rows getting merged because part numbers can be the same while used on more than one part.
I could finally solve this by
Adding a column to my select statement; Parent+'-'+Component As PKey, and group on this and leave the recursive parent and it should worked (Now it properly shows duplicated parts).
My problem is now I lost the drill down functionality.
Although I toggle the visibility of detail row to component, by any reason, the small + and - disappear and I no more can drill down.
Any suggestion how this can be solved.
Assume this is my test table
DECLARE #Test TABLE(Component NVARCHAR(20),Parent NVARCHAR(20),Qty INT,Descr NVARCHAR(20))
INSERT INTO #Test VALUES
('child1','parent1',0,'Desc 1'),
('child1','parent2',0,'Desc 1'),
('child2','parent2',3,'Desc 1'),
('parent1','GrandParent1',0,'Desc 1'),
('parent2','GrandParent1',0,'Desc 1'),
('parent3','GrandParent1',0,'Desc 1'),
('GrandParent1','GrandParent1',0,'Desc 1')
SELECT Component + Parent as PKey,* FROM #Test
in SSRS I created a detail group, group by Pkey and recursive parent(In advanced tab) as Parent.
the visibility of the details group is toggle by Component currently and not working.

I do not entirely understand what your problem is but I come with a possible solution here.
Using the dataset you added to the original question I've created a tablix grouped by Parent and toggled the additional columns visibility to that field.
Create a tablix with the following data arrangement:
Select the Component, Qty and Descr cells (below headers) and press F4 to see the properties windows.
In the Visibility submenu set the properties as the below screenshot.
It will preview the following tablix:
Initially it will hide the details due to True setting in Hidden
property.
Let me know if you need further help.

Related

jasper report show count on footer of a specific query

am very new to jasper report
also I have tried looking at videos but can not seem to get this one concept
basically there is this main query which i have
select * from table
which is populated in the details area
however i want a second query
select count(*) from table where name = "tim"
and put the count on the footer
can this be done using jasper
any tutorial to this concept or guidance would be helpful
to sum up the details area should show all the data where as the footer should only show counts of a few things.
You can only have one DataSet (therefore query) for the report. In your case this is your main report select * from table, which seems to be working well.
You have two options for adding the information you want:
(and I would say the better option) is to add a variable $V{tim_count} which is configured as:
initial value 0
expression value "tim".equals($F{name}) ? 1 : 0"
calculation function sum
there are multiple ways to increment this variable, so I'll leave that with you. In the footer you would then add a text field with the $V{tim_count} variable as it's contents.
You can read about variables here https://community.jaspersoft.com/wiki/variables
You can add an object that has it's own DataSet:
Table
List
Subreport
You would then be able to add your query to that object and display it appropriately. As you can see, displaying a COUNT is not really the most appropriate way to do this.
Note - I don't suggest this way

How do I use the Detail Section when I have multiple Tables

I recently had to take over creating reports using CR 2013, but the introduction I got was kinda lackluster, so from time to time I run into some Problems.
Recently I had to use the detail section for the first time since I was somehow able to handle previous reports with just grouping and Subreports.
Now, what I was doing was create a report listing certain personal assets for each person in a table.
First I grouped by Organisation, then by Person and then put the field with their assets into details.
This worked fine until I was supposed to attach a subreport that should only be shown if it contains any records.
In my first attempt I attached the subreport in the report-footer and suppressed the section if the ID-Field for the main object of the Subreport was Null.
But that caused all personal assets in the detail-section to be duplicated, I guess because it reprinted the details for all records in both the table of the original, and of the subreport.
I solved this by removing the table from the main record and suppressing the subreport within itself.
But is there a solution to only print a detail section for the records of a specific table? Is there even a reason to do that? I am asking since I want to be sure I understand such concepts going forward.
Thank you in advance.
I understand that the introduce of the second table caused the repetition of details because it lead Crystal to make a cartesian product of the two tables.
Let's call the two tables like this to facilitate: TableA, TableB.
When you use only the TableA, think that Crystal do this:
select * from TableA
Then you introduce TableB, then Crystal would do this (just a mental model, I am not saying it does it really):
select * from TableA, TableB
If you understand SQL, you will notice what happens: a combination of all elements in both tables.
Then, the details section will consider each result of this combination.
Ex: TableA = {1,2}; TableB = {X,Y}; Result = {1X,1Y,2X,2Y}
In general, there are two approachs to avoid this. I don't know which one is applyable, since I don't know all the details of your case.
Let your main report know about the TableA only and the subreport know about the TableB only.
Create an extra group (surrogate, innermost). It should group by an unique value in TableA (an Id value would be great). Then you move the fields from details section to this new group footer section and suppress the details section.
There is another approach: create a link between both tables, but it is possible depending on the data, so I can't claim it will work. That would lead to Crystal to do something like:
select * from TableA, TableB where TableA.Id = Table.ReferenceToA
And it would possibly remove the repetitions.

Erroneous duplicate rows in BIRT report

I have a problem with a BIRT report I'm working on where I have a nested table in the report. The outer table contains data to do with an item on an invoice, while the inner table contains stuff to do with price banding for labor charges. I've written a separate DataSet which gets the inner data, bound by parameters to data in the outer table. Now, when I preview the inner DataSet in BIRT using the defaults I've given it, it returns two rows of data for that bill number & item number - a normal rate & an overtime rate if you like. When I run the report in full over the same data, the outer table stuff is fine, but the inner table just repeats the same row over twice - it's just the first row repeating.
This is sorta what the table looks like in layout view:
Item Description Rate Quantity Item total
[item] [desc] [rate] [quantity] [total]
...where the price & quantity are in the inner table.
I'd have expected to see something like:
Item Description Rate Quantity Item Total
1 Callout $40 1 $40
2 Labor $30 4.5 $185
$50 1
but instead I get more like:
Item Description Rate Quantity Item Total
1 Callout $40 1 $40
2 Labor $30 4.5 $185
$30 4.5
...even though querying the database & previewing the inner data set based on the same input criteria show the expected result.
Has anyone else had experience like this? I have a hunch it's to do with bindings, but not sure what.
One way to get this behavior is by accidentally replacing a table-level binding with a column-level binding.
For example, define a table by dragging a data set into the report. Select the entire table (use the outline view, or select something in the table and then click on the "Table" button that pops up just below the grid.) Then go to the Binding tab. Note that the data set and column bindings are all filled in.
Now select just one field in the Detail row. On the Binding tab, note that the Data Set is blank, and no column binding is shown. Someone who is confused by this (as I was) might then edit the column's binding and specify the same Data Set that was used to create the table. If you do this you will only see a single value repeated in that column when you run the report. (I believe the overridden column is binding to a second instance of the data set, not the one the table is iterating over.)
Not sure your question can be answered withou looking at the data and the design. But it is important to note that the results you see in the dataset preview, and not neccisarly what you would see if the query was run fully. I have seen difference with 7 records returned. I thought as it was only 7 it would be the same on full run, but it's not. The preview is not just a top 500 query, it has some other (not sure what) filters also.
To problem solve if it is your query or your binding.
If you are using a SQL database. Run the SQL in a SSMS query and see if you get the same results you do when run in the innner table.
Altentively, create a new test report, copy over your dataset and use with a stand alone table.
I think I sorted it, & this is the most bizarre thing: On the child table I'd been deleting the header & footer row & just leaving the detail row in, in the layout view. Last thing today, just before I was going to go home, I tried again - deleted the table for about the 70th time that day, replaced it, re-did the parameter bindings all exactly as before, but this time I left the header row & footer intact. Clicked the preview tab, voila, all shows up correctly. So, since I didn't need the header or footer on the child table, I went into properties, clicked Hide this element, preview again - all good. No difference to the data bindings, no difference to mappings or anything else, no change to the data sets - the only difference was leaving the header & footer in place but hidden.
Contemplating making a bug report, tbh.

Hide duplicate row SSRS 2008 R2

Duplicated data is coming in my report because source table has duplicate data. Without creating group, I want to hide duplicate data writing expression. So what I did: I select table row and put a expression for hidden property of table row.
The expression was like =(Previous(Fields!ID.Value) = Fields!ID.Value)
but it did not work ... Still duplicate data is showing. So tell me how to suppress duplicate rows in ssrs writing expression not by grouping.
You probably should try these options first:
Try to clean the duplicate data at the source.
Change your source query so the duplicates don't appear in the dataset. (e.g. SELECT DISTINCT)
If not, on the row's Visibility Hidden property you can use the Previous function:
=iif(Fields!YourField.Value = Previous(Fields!YourField.Value), True, False)
You would have to sort on the YourField column for it to work.
I was putting the expression above also until I started using the "Hide Duplicates" line in the properties pane. You basically just select the row, in the dropdown choose your Dataset and that's it. any duplicates will be hidden. Also if you just want to hide certain textboxes duplicates you can do the same as i stated earlier except click on the textbox and not the row. Just another alternative, i'm aware you said using an expression.
You can do it using expression or "Hide Duplicates" options from cell or row properties.
Expressions :
=IIF(Fields!YourField.Value = Previous(Fields!YourField.Value), True, False)
Hide Duplicates Steps:
Select row or cell
Click on F4 key on your Keyboard
Look for "Hide Duplicates"
Choose your DataSet from the dropdownlist
Done, I hope that helps
As an alternative option, you can do it by setting row groups. In a report I was trying to create, the Hide Duplicates property wouldn't behave correctly because of using the same dataset multiple times in a list container.
All you need to do is set the row group properties for the default row group (rightclick the grey row header, and go to Row Group then Group Properties), and add Group expressions on the General tab. Add as many as you need for each field. It's like the Remove Duplicates tool in Microsoft Excel
Sometimes the Hide Duplicates option does apply to the report content. If you add a =Sum(Field!Field_Name.Value) sum around field in the cell, it suppresses the copy from previous record. Of course, strictly speaking this is a solution where the incoming data set has NULL rows for the cells with the issue.
Since the using of Previous function in SSRS compare to the only record previous to it, thus it might cause the duplicate of records still shown if the repeated records not next to each other.
Use the sorting on each table you apply the Previous function, it should resolve the "non next to each other" duplicate records as well.

Is there a way to select records from text parameters after run time in Crystal Reports?

I need to design a crystal report with 3 columns. Column 1 is a text box in the report, and column 2 and column 3 are datafields from a particular table.
Is it possible for me to use column1 as a parameter that would help me to fetch the other columns from the database??
col1 col2 col3
TextBox value1 value2
so when a user changes the value in TextBox, col2 and col3 value should reflect based on textbox value.
Or is there any other way in which i can achieve this??
There is no way to interact with a report the way you want via text boxes after the report has run. Since you can't select records on the fly, you'll have to create a report parameter of the same type as your primary keys (column A) and then set it to "Allow multiple values". You'll be able to select only the records you're looking for at run time by adding {table.colA} in {?Parameter1} into your Record Selection formula.
Drop {table.colA} and {table.ColB} into the Details section of the report. Now when you run it you can just add your 15 items as the parameter and you'll get what you're looking for.
Alternatively, if its important for the user to interact with the report after it's presented, you could accomplish this using (1) sections/grouping and Crystal's Hide option or (2) an on-demand subreport.
For example, you could group by column1, and then print a detail section for all the values. Mark the detail section Hide. Then, when you click on the value, that section will expand.
Or instead of marking it Hide, mark the group footer (for column1) New Page After Section. Then you can use the document tree along the left side to navigate to the page containing the values you're interested in seeing.