Crystal Reports - Create subreport with column range [col1...col60] as datasource? - crystal-reports

I am adept in both SQL and CR, but this is something I've never had to do.
In CR, I load a table that will always contain 1 record. There is a range of columns (like Column1, Column2 ... Column60). (bad design, I know, but I can't do anything to change that).
Thanks to this old design I have to manually add each column in my report like this:
-----------
| TABLE |
-----------
| Column1 |
| Column2 |
| Column3 |
| ... |
-----------
Now I would like to be able to create a subreport and create a datasource for it in such a way that [Column1...Column60] becomes a collection [Row1...Row60]. I want to be able to use the detailsection of the subreport to dynamically generate the table. That would save me a lot of time.
Is there any way to do that? Maybe a different approach to what I had in mind?
Edit
#Siva: I'll describe it the best way I can. The table exists out of 500+ columns and will only hold 1 record (never more). Because normalization was never taken into account when creating these tables (Objective C / DBF ages) columns like these: Brand01,Brand02,Brand03...Brand60 should have been placed in a separate table named "Brands"
The document itself is pretty straight forward considering there's only one record. But some columns have to be pivoted (stacked vertically) and placed in a table layout on the document which is a lot of work if you have to do it manually. That's why I wanted to feed a range of columns into my subreport so I can use the detail section of my subreport to generate the table layout automatically.

Ok got it... I will try to answer to the extent possible...
you need to have 2 columns in report that will show the 60 column names as 60 rows as 1st column and 60 column data as 2nd column. For this there are two ways that I can think of.
if columns are static and report need to be developed only once then though its a tough job manually create 120 formulas 60 for row names where you will write column names and 60 for data for respective columns and place in report since you have only one record you will get correct data. Like below:
formula 1:
column1 name // write manually
Formula 1:
databasefield for column1 // this has data for column1
Above will be one row in report like this you will get 120 formulas 60 rows and you don't need sub report here main report will do the job.
Since you are expecting dynamic behavior (Though columns are static), you can create view from database perspective or datatable (Please note I have no idea on datatable use it as per your convinience).
Create in such a way that it has 2 columns in table and in report use cross tab that will give you dynamic behaviour.
In cross tab column1 will be rows part and column 2 will be data.
Here also I don't see any requirement for sub report you can directly use main report. If you want sub report you can use aswell no harm since you have only 1 record

Related

DSUM function in crystal reports?

I am trying to convert an old Microsoft Access report into Crystal reports. I have everything working perfectly except for this last small detail. The Access report uses a DSUM function within an if statement for one of the fields on the report.
After much searching, I've determined that CR doesn't have anything similar.
Here's basically what I'm dealing with.
I have a proposal report. In the details of the report I print the qty, description, and a couple of price fields.
The data looks like something this:
Proposalnum Partitem RolltoItem Unitprice
18611.............1.......... NULL........0.00
18611.............2......... NULL.......17225.92
18611............3............ 2............156.90
18611............4............. 2............482.05
What I need to do is when I print a specific part, I need to query through the rest of the records to find the parts that have a matching number in the rolltoitem field and add the unitprice to the part I'm printing.
So in this example when I print partitem #2, I need to add the 156.90 and the 482.05 from parts 3 and 4 to the 17225.92 so I print a total of 17864.87.
Is there any way to do this?
As far as i know, there is no such function.
But I would try this.
The general idea is: group the data by ProposalNum and use a subreport to select the "children rows" and sum the "children prices".
Details:
Create an empty group section by PartItem.
If you want to show only items where RoolToItem is null, use a suppress function for this case.
In the details section, put a subreport. The data source of the subreport would be the same of the main report.
Change subreport links to select data in subreport based on fields: PartItem in the main report = RolltoItem in the subreport.
Pass other fields to the subreport without select data: ProposalNum, PartItem, UnitPrice. I think you need to create parameters in the subreports before doing that - example: ParentProposalNum, ParentPartItem, ParentUnitPrice.
Create a new formula: ParentUnitPrice + Sum ({YourDataSource.UnitPrice})
Put the formula in the subreport footer a long with the other fields. Maybe: ParentProposalNum, ParentPartItem, formula.
It is a theoretical solution. I hope it points out to the right direction.
If you are trying to sum the Unitprice column for all items that have the same value in Rolltoitem, you could do this with a SQL Expression Field. The code would look something like this. My Where clause may need tweaked though since I'm not sure what your database structure looks like.
(
Select Sum("YourDataBaseTableName"."Unitprice")
From YourDataBaseTableName
Where "YourDataBaseTableName"."Rolltoitem" = *currentRolltoitemValue*
)
Syntax can also vary for SQL Expression Fields based upon what type of database you are using. The syntax I provided is fairly general, but should work on SQL Server.
EDIT: Adding example with explanation of how it works.
Here is one of my SQL Expression Fields from a crystal report that prints a Bill of Lading for shipped goods.
(
Select Sum("SHIPMENTS"."PALLET_COUNT")
From SHIPMENTS
Where "SHIPMENTS"."BOL_ID" = "BOL"."ID"
)
In my database the BOL table is the starting point. A single BOL can contain 1 or more SHIPMENTS, and a single SHIPMENTS can contain one or more PRODUCTS.
Top level grouping is on BOL.ID. The PALLET_COUNT is found once and only once on each SHIPMENTS. I also had a sorting requirement for the data in the details section that prevented me from using a Running Total Field.
This allows a BOL with 2 SHIPMENTS that contains a total of 3 products to look like this:
BOL.ID SHIPMENTS.ID SHIPMENTS.BOL_ID PALLET_COUNT PRODUCT.ID
1 10 1 2 XXX
1 9 1 1 YYY
1 10 1 2 ZZZ
The correct PALLET_COUNT for this BOL should be 3, since PRODUCTS XXX and ZZZ are in the same SHIPMENTS and the PALLET_COUNT is duplicated because of its relationship to the PRODUCTS.

Tableau table filter for one column only in table

I have a really basic question that I can't figure out. I need to create a table that has multiple calculated fields, but I need only one of the calculated fields to be filtered for a specific dimension value. For example, I have the following data set (dummy data) and I want to create a table that will include total clicks for both companies, but [cost per click] from one company only, company B.
DATA SET
Company| Clicks| $ Cost
------------------------
Comp A | 100 | $20
Comp B | 200 | $40
WHAT I'M LOOKING FOR
CLICKS | COST/CLICK
TOTAL 300 | $0.13
$0.13 comes from 40/300; $40 from company B and 300 clicks from both company A and B.
How do you create a table that has multiple calculations but with one of those calculations filtered on one dimension value only?
One simple calculated field:
sum(if [Company] = 'B' then [Cost] end )/sum([Click])
This should get you in the right direction.
Based on your question and your comment, you want to divide the cost by the TOTAL number of clicks in your dataset.
Create a calculated field called "TotalClicks" and enter this formula
window_sum(sum([Clicks])) // This formula will sum the clicks field for all rows
Create a calculated field called Cost / Clicks and enter this formula
sum([Cost]) / [TotalClicks]
Add the Cost / Clicks field to the sheet and it should look like this
NOTE: If you need to partition / group your report, you may have to play around with this some. I don't use window functions within tableau very often since I usually handle the aggregation at the datasource level instead.
NOTE: Since you mentioned filtering, I will add this statement -- If you filter out any of your data, that data will not (cannot) be included in any calculated fields (To the best of my knowledge and experience, anyway). If you need to include that data (total clicks), I think the only option is to add that aggregated total to your dataset - otherwise, tableau can't calculate it if you are filtering it out.
Edit2: If you cannot change the underlying dataset, you could accomplish this by creating another datasource and joining it to your inital data source --
Data > Add Datasource, add the datasource again and change the name so you can identify it
Click Data > Edit Relationships. Click Custom and REMOVE any linked fields -- this will essentially produce a Cartesian join (every record in your first DataSource will have every reocrd from your second Datasource)
Select the second datasource and create a calculated field (ClicksTotal_DS2) using the same window_sum function
Select the first datasource and create a calculated field (named Cost / Clicks_DS2) using this formula
sum([Cost])/ [Sheet1 (test) (2)].[ClicksTotal_DS2]
Now you can apply a filter to your first data source, and your second data source will still calculate the total.

SSRS Double row headers and data display for printing

** I'm using SSRS2008 R2
I have a report that the users would like to see in a printable pdf.
Problem is there are several columns, potentially too many to fit on a printed 8.5x11 paper.
One of the concepts they suggested was a stacked header/data display, like breaking the columns into 2 rows, so 2 rows of data (for John and Bill) would look like this:
NAME START_DATE STATE COMPANY
ACCOUNT BALANCE END_DATE
-------------------------------------------------------
John 1/20/2016 NY GE
10076 $100.00 2/20/2016
-------------------------------------------------------
Bill 5/13/2016 MA Netflix
00013 $150.00 12/31/2016
-------------------------------------------------------
This leads me to 2 questions:
Is there a way to do this with a tablix?
AND/OR in addition, is there a way to set a default property on the report so when the report is exported to pdf and to print, that it defaults to fit all columns on one page (therefor shrinking the font size to fit on page?)
For anyone that cares - Apparently this can easily be achieved by dragging a Tablix onto the work area, right clicking the header row, adding a new row underneath (basically becomes header row 2), then do the same thing to the details row - however make sure to insert row - Inside group. That allows you to have stacked header and data rows and you can copy / paste headers and row values in whichever row you'd prefer.
it will work if you make all the columns on the same height not unequal. If all the columns has same height, then while exporting to pdf/excel and print it will come in the same page.

Crystal Reports 7 CrossTab Suppress Column

I'm trying to modify a report created in Crystal Reports 7 (which I know almost nothing about). I want to use a CrossTab, as this seems to be the best way to accomplish what I want. I have a column with three possible values: A, B, C. The cross tab creates three columns. I want to suppress C. How can I do this?
Also, is there anyway to create rows based on one field (i.e. a PK value), but display another - like a description? For example, if a list of states have a PK value of 1-50, I want them ordered by PK, but I want to display the state name.
All you ask is possible;
i suggest not to use cross tab: cross tab is intended for an uknown number of rows and columns (varying on data) ad for summarizing (max value, sum of values) results on a grid.
you should, instead:
Create a blank report
Drop the fields from the Field explrorer into the Details Section (just A and B columns)
Use Report Sort Expert to sort elements no the PK value

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.