|
-
January 14th, 2011, 01:33 AM
#1
problem with formulas
I've only stated to work with crystal reports recently so im still learning how to create reports, the version im using is 2008
I have an orders table that looks like this
Code:
------------------------------
amount | payment_type |
------------------------------
10 | Cash |
15 | Credit |
15 | Cash |
24 | Check |
------------------------------
what im trying to do is create a formula that would only sum up the amounts a payment type
eg. I want the formula to give me the total for the orders that were paid by "CASH"
here is the formula im using:
Code:
Local CurrencyVar ordersCash := 0;
Local NumberVar i := 0;
While i < {@totRecords} Do
(
if "CASH" in {DailySales.payment_type}
then
ordersCash := (ordersCash + {@amtPaidByOrder});
i := i + 1;
);
ordersCash;
the idea is to use a while loop to go through all the rows on my query but it keeps giving me strange totals, so far i am failing to understand the logic CR is putting out, im not even sure if im using the right aproach here so if you could point me to the right direction i would really appreciate it
-
January 14th, 2011, 12:16 PM
#2
Re: problem with formulas
Try with the next formula and place it in the Details Section
It will execute every time a new row is printed
It's value will be incremented every time the condition is meet
If you want the last value you may place ALSO in some section footer
Code:
numberVar ordersCash;
If {DailySales.payment_type} = "CASH" Then ordersCash := ordersCash + {@amtPaidByOrder};
ordersCash;
JG
Last edited by jggtz; January 14th, 2011 at 12:23 PM.
-
January 14th, 2011, 01:07 PM
#3
Re: problem with formulas
*EDIT* -- SOLVED! i was able to figure this last question, what i ended up doing is creating a sub report that is displayed on the Report Header of the parent report
all this help me to understand a little better how crystal reports work thanks again --
jggtz thanks that formula worked but as you say i need to place it on the details section, now im trying to place that formula before the details view, let me show you a layout of the report im creating
Code:
-----------------------------------------------------
RH | |
Summary | *graph* |
*formula here* | |
| |
PH -------------------------------------------------
order headers
D---------------------------------------------------
D order
D order
i want to place that formula in the summary part of the report which i have placed on the RH
is there a way to maybe place that formula on the details but that it displays it results on RH just like it does on footer or im I missing something here, thanks for the help.
Last edited by mrjavoman; January 14th, 2011 at 04:00 PM.
Reason: problem solved
-
January 14th, 2011, 07:56 PM
#4
Re: problem with formulas
You may declare a Shared variable in the subreport and use that variable in the main report
Follow the next link, it may help you to understand a little more
http://it.toolbox.com/wiki/index.php/Shared_Variables
If You place a formula field in Detail Section then you can use that formula field in sections below Detail Section
Also it could be good to google "Crystal Reports shared variables"
JG
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|