Solved

How to pass data from detail section as input of formula in Crystal Reports

Posted on 2014-09-16
9
301 Views
Last Modified: 2014-09-17
For Example :
Crystal Reports "Detail Section A - Sorted By Customer ID 001" - data show as below

ITEM NAME   SHELF NO    QTY

Item A             1                   12,000
item B             2                   14,000
item C             2                   10,000
item D             3                   12,000

Crystal Reports "Detail Section B - Sorted By Customer ID 002" - data show as below

ITEM NAME   SHELF NO    QTY

Item E             4                   16,000
item F             4                   10,000
item G            5                   18,000
item H            6                   14,000


How do I count the percentage of QTY by SHELF NO for each Customer ID?
The results look like :

Customer ID 001
           SHELF NO 1 : 25% ((12,000) / (12,000 + 14,000 + 10,000 + 12,000))
           SHELF NO 2 : 50% ((14,000 + 10,000) / (12,000 + 14,000 + 10,000 + 12,000))
           SHELF NO 3 : 25%
Customer ID 002
           SHELF NO 4 : 44.8276%
           SHELF NO 5 : 31.0345%
           SHELF NO 6 : 24.1379%

No need to get report like this - just like to know how to pass SHELF NO and QTY into formula or any other way also can get the same result.
Please help
0
Comment
Question by:City_Of_Industry
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40326783
From:
http://devshed.us/Blogs/tabid/227/EntryId/31/Percentage-of-Total-field-in-a-Crystal-report.aspx

{myDatasource.QTY } % Sum ({myDatasource.QTY})

Open in new window


I would assume this could also go in the group footer.
0
 

Author Comment

by:City_Of_Industry
ID: 40326807
To be more specific - I need all those number of percentage as variables and use them as one element of formula in other sub-report's detail section
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40327065
To accomplish this you need to

1.  Group by the Customer ID
2.  Group by the Shelf No

Shelf Percent is calculated with

Sum({Qty},{Shelf Number}) / Sum({Qty}, {Customer ID})

Put the formula in the Shelf Group Header or Footer

mlmcc
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 34

Expert Comment

by:James0628
ID: 40327612
... and use them as one element of formula in other sub-report's detail section
You want to pass these values to a subreport?

 Assuming that the answer is "Yes" ...

 Where is that "other" subreport?

 Since you said "other" subreport, where are the quantity values that you're using to calculate those %'s located?  Are they in the main report or in a different subreport?

 The answers to those questions may determine the answer to the following question:
 Are you just trying to pass the values (%, etc.) for one shelf at a time to the subreport?
 Or are you trying to pass the values for multiple shelves, maybe all of them, to the subreport at the same time?

 James
0
 

Author Comment

by:City_Of_Industry
ID: 40328305
Thank you James,

                 I was trying to pass all percentage (SHELF NO 1 - 25%, SHELF NO 2 - 50%, ...) to another subreport in same main report (For example : This main report contains five subreports : subreport 1, subreport 2, ... subreport 5 (they are from different tables)

                 Subreport 1 - have all ITEM NAME, SHELF NO and QTY information - Can I pass all percentage data - calculated from subreport 1 (or all ITEM NAME, SHLEF NO and QTY) data to subreport 5 in same main report? (I tried but only get the first row of data - Item A from subreport 1 Detail Section)
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 400 total points
ID: 40328388
To really be able to help with this we probably need to see the report file so we can understand where the subreports are and the data available to them.

How are you passing data that you only get 1 row?

Are you SHARING an array variable?

The basic method of takes 3 formulas

Main Report - I generally put this in the report header

WhilePringintRecords;
Shared NumberVar Array Percents;
''

Open in new window


In the subreport you would build the array

WhilePringintRecords;
Shared NumberVar Array Percents;
Local NumberVar Index;

ReDim Preserve Percents[4];
For Index := 1 to 4 do
   Percents[Index] := Some Formula;
''

Open in new window


In the other subreport (must be in a section after the subreport that fills the data)

WhilePringintRecords;
Shared NumberVar Array Percents;
 CODE TO USE THE ARRAY OF VALUES

Open in new window


mlmcc
0
 
LVL 34

Assisted Solution

by:James0628
James0628 earned 100 total points
ID: 40328769
If you want to pass multiple values for multiple fields (eg. SHELF NO and QTY), then you may need multiple arrays.

 A CR array can have up to 1000 elements, so if SHELF NO will always be 1000 or less, then you could use that as the index for the array(s).  The data for shelf 1 goes in the first element in the array(s), the data for shelf 12 goes in the 12th element, and so on.

 If shelf # could be > 1000, then you'd need to store each shelf # in one array, and store the quantity for that shelf in the corresponding element in another array.  The first shelf # and quantity go in the first elements of the arrays, the second set of values goes in the second elements, and so on.


 Your last post indicated that you also want to pass ITEM NAME, but in your first post, you seem to be ignoring that for your totals.  For example, you have shelf # 2 with "item B" and "item C", and you just combined those for the total.  If you want to pass ITEM NAME too, that will complicate things.

 James
0
 

Author Closing Comment

by:City_Of_Industry
ID: 40329114
Thank you James and Michael

As non-programmer and in one man Dept. , I spent lots of time to googling and figure out the solution (Array) according to your guidance. Currently I can pass whole set of data from one subreport to another subreport as elements of formula in there.
I learned a lot from both of your answer above, I really appreciate your help.
Thank you again
0
 
LVL 34

Expert Comment

by:James0628
ID: 40329247
You're welcome.  Glad I could help.

 James
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now