Solved

Calculate three fields

Posted on 2013-06-21
5
241 Views
Last Modified: 2013-06-24
Running CR 10

Looking for profitability using 3 fields. Two fields are in one table and one is another, all display currency records. One of the fields only returns currency when it has data otherwise its blank which is causing problems trying to calculate using the other fields. Below are the fields and sample data:

tblSO.sellprice
tblSO.cost
tblsubcontractor.cost

                           sellprice   socost    subcost
SO No. 12345   $200.00    $100.00  $50.00                
SO No. 23456   $100.00    $0.00      
SO No. 34567   $300.00    $100.00  $100.00

I need to calculate the profit using the fields but because SO No 23456 is blank the formula I'm using is not calculating correctly. Using the formula below shows a profit of $100.00 (seems to only be using the last row instead of all three) should be a total profit of $250.00.

{tblSO.sellprice} - ({tblSO.cost} + {tblsubcontractor.cost})

Formula is used in GH1 (tblSO.sonumber) and RFa
0
Comment
Question by:BERITM
  • 2
  • 2
5 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 39267457
In the formula editor there is a drop down.  The default setting is EXCEPTION FOR NULLS
Change that to DEFAULT VALUE FOR NULLS

The other way to handle this is to use formulas for the values or NULL tests in the sum formula

Formula SellPrice

If IsNull({tblSO.sellprice}) then
    0
Else
    {tblSO.sellprice}

Formula Cost
If IsNull({tblSO.cost}) then
   0
Else
   {tblSO.cost}

Formula ContractorCost
If IsNull({tblsubcontractor.cost}) then
   0
Else
   {tblsubcontractor.cost}

Your sum formula changes to

{@SellPrice}  -  ({@Cost} + {@ContractorCost})


You can also do this in a single formula

Local CurrencyVar total;
If NOT IsNull({tblSO.sellprice}) then
    total := total + {tblSO.sellprice};

If NOT IsNull({tblSO.cost}) then
    total := total + {tblSO.cost};

If NOT IsNull({tblsubcontractor.cost}) then
    total := total + {tblsubcontractor.cost};

Total

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
ID: 39267913
mlmcc,

 The last formula should be subtracting the costs, right?

 James
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39268260
Actually the last 2 should be subtracting

Local CurrencyVar total;
If NOT IsNull({tblSO.sellprice}) then
    total := total + {tblSO.sellprice};

If NOT IsNull({tblSO.cost}) then
    total := total - {tblSO.cost};

If NOT IsNull({tblsubcontractor.cost}) then
    total := total - {tblsubcontractor.cost};

Total

Open in new window

0
 
LVL 34

Expert Comment

by:James0628
ID: 39268654
Yeah, that's what I meant ("costs" was referring to both cost fields).

 James
0
 

Author Closing Comment

by:BERITM
ID: 39271899
Thank you very much, the formula worked perfectly!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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