Solved

Calculate three fields

Posted on 2013-06-21
5
240 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
Comment Utility
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
Comment Utility
mlmcc,

 The last formula should be subtracting the costs, right?

 James
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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
Comment Utility
Yeah, that's what I meant ("costs" was referring to both cost fields).

 James
0
 

Author Closing Comment

by:BERITM
Comment Utility
Thank you very much, the formula worked perfectly!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now