I have a question about Crystal Report. I have an existing report, with its data taken from a stored procedure. The data may look like this:
Division|Group Level 1|Group Level 2 |Group Level 3|Value
--------+-------------+-------------------+-------------+--------
IT |Assets |Current Asset |Cash |100
CORP |Assets |Current Asset |Cash |200
IT |Assets |Current Asset |Receivables |300
CORP |Assets |Current Asset |Receivables |400
IT |Assets |Fixed Asset |Land |500
CORP |Assets |Fixed Asset |Land |600
IT |Liabilities |Current Liabilities|Wages |100
CORP |Liabilities |Current Liabilities|Wages |200
IT |Liabilities |Current Liabilities|Taxes |100
CORP |Liabilities |Current Liabilities|Taxes |100
IT |Liabilities |Long-Term |Bonds |300
CORP |Liabilities |Long-Term |Bonds |400
The actual data may have many more divisions (not just two). In the new report, I want the report to look like the following:
| IT | CORP
Current Asset
Cash | 100 | 200
Receivables | 300 | 400
Total Current Asset | 400 | 600
Fixed Asset
Land | 500 | 600
Total Fixed Asset | 500 | 600
Total Assets | 900 | 1200
Current Liabilities
Wages | 100 | 200
Taxes | 100 | 100
Total Current Liabilities | 200 | 300
Long-Term
Bonds | 300 | 400
Total Long-Term | 300 | 400
Total Liabilities | 500 | 700
So, the report will be expanded to the right, according to the number of divisions. Assume that one page can hold up to 10 divisions. Then if there 15 divisions, then the first page will show division 1 to 10, the second page will show 11 to 15. The items shown on the first and second page will be the same, just for different divisions. The number of divisions are flexible. And also the items are quite a lot (there can be a lot of current assets, liabilities, etc).
For now, I tried to do some formatting in the stored procedure, so the returned data will be like:
Page No | Group Level 1 | Group Level 2 | Group Level 3 | Div 1 | Value 1 | Div 2 | Value 2
--------+---------------+---------------+---------------+-------+---------+-------+--------
1 | Assets | Current Asset | Cash | IT | 100 | CORP | 200
1 | Assets | Current Asset | Receivables | IT | 300 | CORP | 400
and so on.
For division 11 to 15, I set the page no to be 2. And then in the Crystal Report, I will group by : Page No, Group Level 1, Group Level 2, and Group Level 3.
So the Crystal report will show everything on a page based on the page number.
The problem is that:
- If there are a lot of items, then it may not fit in one page as well. For example, assume one page it can fit up to 30 lines, then if I have 40 lines, the 10 lines will be shown in the second page.
But I want the second page to still show the first 30 items for division 11-15, and the third page will show the last 10 lines for division 1-10, and the fourth page will show the last 10 lines for division 11-15.
- The running total in Crystal Report will be reset on each change of the group. Let say I have 40 assets. Then after the 40 assets, which is on the third and the fourth page, it should show the total of the assets. How do I calculate the running total so that it shows up correctly? (Considering I can not just sum it up directly, as third and fourth page should show the total of different divisions).
Is there any solution for this problem or a better approach to format the data?
Thanks.
What is your exact issue?
Formatting the report or calculating running total?
Implement below process
Create a group with "Grouplevle1", Don't supress Group1 Header
Create a group with "Grouplevel2", Don't supress Group2 Header. Create two text filds and write "IT" and "Corp" and place on report
Create a group with "Grouplevel3", Now supress the group3 header
Write a formula and add below code
If Divison="IT"
Then Value
Else o
wirte another formula and add below code
IF Divison="Corp"
Then value
Else 0
Place both forumula in detail and add summary to all sections.Also supress detail section
For all group footers write required text
This will solve your problem.
I would recommend using a cross-tab.
Settings:
Columns: Division
Rows: Group Level 1, Group Level 2, Group Level 3
Summarized Fields: Value
You'll have to experiment with the row-grouping fields to get the correct spacing. Do the same for the column's sizing.
In general, this is how I finally solve the problem:
1. Define how many divisions (NumColumn) to be displayed in a single page.
2. Create a table to store the mapping of the division. The table has column that stores PageOffset and ColumnNo. PageOffset stores the number of page to be added when displaying a particular division. For example, if there are 15 divisions, and a page can only accommodate 10 divisions, then the first 10 divisions will have `PageOffset = 0` and the last 5 divisions will have `PageOffset = 1`. The ColumnNo is the position of a division in the report column. So first division will have value of 1, second division will have value of 2 and so on. 11th division will have the value of 1, etc.
3. Create a result table. For each column in the report, we have 2 database field, value and total.
4. Loop for each record, sorted by the group.
Select the position of the division from the table in step 2. If `ColumnNo = 1` insert a row in the result table. E.g. for division 1 and 11 it will create rows in result table.
After that update the row data, based on the position of the division. So for division 1-10 will update the row created by division 1, division 11-15 will update row created by division 11.
5. Count the number of items in each group and store it into a table.
6. Define how many rows (RowsInPage) to be displayed in a single page.
7. Set PageAdd = 0 and RowsLeft = RowsInPage
8. Loop for each group
Retrieve the number of rows needed for this group
Add the page number of each row with PageAdd
Decrement RowsLeft
If RowsLeft = 0
Increment PageAdd
Set RowsLeft = RowsInPage
End If
9. Loop for each group
Loop from 1 to NumColumn
Update the total field for each division. This total field value will be put in the report as the running group total for that particular division.
Related
using SSRS 2008 R2 here.
I've been able to get a similar layout to work with a regular tablix, where I get each group header to fall on top of each other in the same column by adding a row within that group, however I need to use a Matrix because of a dynamic column (month below). When I try to add another row, it only adds a row where the monthly data starts, not in the headers. So the headers stay in their each column. In trying to keep the example as easy as possible, I'm trying to do something like this (Store theme).
STORE NAME | MONTHS
STATE | SALES
TOWN(S) | SALES
which woudl look something like this in a Matrix
WALMART JAN FEB MARCH etc....
TEXAS | 3000 2000 6000
HOUSTON | 1000 500 2500
AUSTIN | 2000 1500 3500
I've only been able to produce something like this where each group is a seperate column:
STORE | STATE | CITY | JAN | FEB | MAR |
WALMART | TEXAS | HOUSTON | 1000 | 500 | 2500 |
| AUSTIN | 2000 | 1500 | 3500 |
Again, I've been able to get a regular Tablix formatted like this, but a Matrix I'm struggling with. Can anyone help me on how to do this? Thank you in advance!!
It is possible using a tablix/matrix and adding some special grouping settings.
Add a tablix with the City field in Row Groups pane:
Right click the City group, select Add Group / Parent Group. Choose State and set Add a Group Header
Delete the left most column (State column added in the previous step).
Note the group is still present.
Right click the STATE group and add a Parent Group as step 2. In this case choose STORENAME
Again delete the left most column (Store Name column added in the previous step)
You will get the following tablix.
Delete the first row
Set the Fields using the Row Group hierarchy order. STORENAME/STATE/CITY
Right click the first cell in the next column and add a group / Column Group / Parent Group. Choose MONTH in group by.
Delete the first row.
Set SUM(Fields!Sales.Value) in the next cells in the same column.
After these steps you will get a tablix like this in design window.
It should produce:
Let me know if this helps.
I made a table like
record
----------+
1 | one |
----------+
2 | two |
----------+
3 | three |
----------+
4 | four |
----------+
5 | five |
----------+
There isn't an ID column, those are just the row numbers I see beside each row in DBVisualizer. I added the rows in the order 1, 2, 3, 4, 5. Is this"
SELECT
*
FROM
sch.test_table limit 1;
certain always to get one, ie start with the "oldest" record? Or is will that change in large datasets?
No, as per the SQL specification the order is indeterminate when not using order by. You're working with a set of data, and sets are not ordered. Also, the size of the set should not matter.
The Postgresql documentation says:
If ORDER BY is not given, the rows are returned in whatever order the
system finds fastest to produce.
Which means that the rows might come back in the expected order, or they might not - there are no guarantees.
The bottom line is that if you want deterministic results you have to useorder by.
I have a group running total that needs to be sum up at the report footer. Since thats not possible with CR I had to end up having another running total that refreshes "Never". But now I need to calculate some percentages at the group level based on this Grand total. Unfortunately I cannot access the value for grand total (because its another running total).
Confused?? Ok reports should look like below..
Column 1 | Colunm 2
======== =========
| Group 200 (Running Total Refresh at Group level) | 20% (200%1000) |
| Group 500 (Running Total Refresh at Group level) | 50% (500%1000) |
| Group 300 (Running Total Refresh at Group level) | 30% (300%1000) |
Footer 1000 (Running Total Never Refreshed)
But column 2 doesn't give me the correct value. it gives me 100% always means 200%200 or 500%500 etc.
Any idea how to fix this??
Thanx Lee, using a running total formula worked, I added following formula to the report footer,
numbervar Samples;
if {product.sku}="card-sample" then
Samples := Samples + {#num_qty};
Samples;
Then I use this formula to calculate column 2
Try this
Add a formula field for group percentage and then paste below code in it.
Group total / sum(column)
place this formula at your group level.
I should think your report total wants to simply be a summary field not a running total. Then your column 2 value can be calculated using running total / sum(field);
Here is an example:
I have two columns age and salary.
When age > 18 i want to add the salary.
Initially I used a running total with a condition {age} > 18
That didn't work well so i deleted the running total, and created a formula: if {age} > 18 then {salary} else 0
I then created a summary on that formula field.
Make sense?
so I'm working with Crystal Reports 10 and was looking at the cross tab to try and have a nice and neat table of my information. I'm trying to make a report where for each item (as a row), the columns will be the different sizes it comes in and the value of that cell will be the quantity.
So something that looks like this:
Small | Medium | Large
Item 1 1 | 5 | 10
Item 2 5 | 10 | 15
Using the cross tab though, the quantity field I have has to be totalled, averaged, etc. so I can't get the specific breakdown for each size in a nice table like that. Is there any way to tweak the Cross Tab to do this or is there another tool in Crystal Reports that would let me have the quantities per size in that organized fashion?
Thanks for any help you guys can give.
Update:
The cross tab I have tried gives me something that looks like this
Small | Medium | Large
Item 1 16 | 16 | 16
Item 2 30 | 30 | 30
If I put the values in the details section as separate fields, I'm able to get the values to match up properly, but its not the right format. It comes out like this
Item 1 | Small | 1
Item 1 | Medium| 5
Item 1 | Large | 10
Create a Cross-tab
Add {table.size} to the Columns
Add {table.item} to the Rows
Add {table.quantity} to Summarized Fields
I am working on SSRS 2008.
I have a report as follows, I want the toal of Amount in Total column. I am not able to get total in column. I have tried Add Total / Sum() features of SSRS but no luck.
+---------+-------+--------+-------+
|Supplier | Agent | Amount | Total |
+---------+-------+--------+-------+
| | A10051| 237.2 | |
|S2005068 +-------+--------+ |
| |A10052 | 23.8 | |
+---------+-------+--------+-------+
I think your design is not proper. The total row in the last column will be under the details group. If you want a total on the last column you can get but for-each row it will repeat. use
=Sum(Fields!Amount.Value,"Supplier") here Supplier is the "Group Name"
To avoid this repeatition we need to add the total column inside the supplier group and use =Sum(Fields!Amount.Value) for total
or
Right click on the Amount column data -> Add Total -> Before or After. This will display the sub-total for the Supplier group in the same Amount column after/before as you selected.
Add total on the supplier group, add it before or after, depending if you want it on top or bottom. SSRS will fill in =SUM(Fields!Amount.Value) and show the total 268 below.
To make a Total Rows =countRows("dataset")