8 Replies Latest reply on Feb 26, 2009 7:42 AM by ninja

# Calculation

### Title

Calculation

### Post

I am trying to have my filemaker do a calculation but am not sure how to go about it.

I have a table with Different charge codes, and then another table for receipts and the  amount for each receipt. There is only one  charge code that needs to be calculated to have a 5% of the amount charged.

So here is an example.

I have a receipt for \$45.00 i enter it into my database and it is coded to charge code 008, now charge code 008 requires a 5% charge on top of the 45 dollars but none of the other charge codes do. So I want to have a field that will only calculate 5% onto the amount of the receipt if the 008 charge code is used.

Lesley

• ###### 1. Re: Calculation

howdy sweetcuda,

Thanks for the post.

This one is a simple "If".

If(CodeTable::Code="008";RecieptTable::Amount * 1.05;RecieptTable::Amount)

how does that do for you?

• ###### 2. Re: Calculation

That works perfectly for the amount that I want to percentage to show. but I would also like if the other codes which to not have the 5% calculated, for the amount not to show or for it to show a zero in that field.

Right now the calculation is perfect

I have 94.00 for a receipt and I have Surcharge fee as 4.70 if it has code 008, but then I have a receipt for 50.00 for code 009 and it shows up in the surcharge fee calculated feild as 50.00.

Is there a way to have this field be blank if it doesnt meet the 008 requirement? or have it calculate to 0.00 instead of the receipt price if it doesnt meet the code if statement.

Thank you

• ###### 3. Re: Calculation

Sure thing sweetcuda,

Think it through with me here...the "If" statement works like this:

If( Test This  ;  Do this if it's true  ;  Do this if it's false )

If(CodeTable::Code="008";RecieptTable::Amount * 1.05;RecieptTable::Amount) returns Amount*1.05 if it's true and Amount if it's false.

If you want to change what happens when the test Code="008" is flase, then do so.

If(CodeTable::Code="008";RecieptTable::Amount * 1.05;"0" ) returns "0"

If(CodeTable::Code="008";RecieptTable::Amount * 1.05;"" ) returns a blank

If(CodeTable::Code="008";RecieptTable::Amount * 1.05;"sweetcuda" ) returns "sweetcuda"

Is this what you're after?

• ###### 4. Re: Calculation

Ninja,

Thank you so much for your help and the wonderful explination. I have never really worked with calculations and your explination was so helpful. You are Awesome!!!! I love the sweetcuda return for one of the calculations. LOL

Thank you,

Lesley

• ###### 5. Re: Calculation

How would I write an if statement for two different charge codes.

Example.

I have the "008" which I have calcuating at 0.0842 (works great)

But now I also want the same field to calculate if a charge code is "009" to multiply the dollar amount by 0.05.

I tried just adding Or to the end of this statement

If(CodeTable::Code="008";RecieptTable::Amount * 0.0842;"0" ) Or If(CodeTable::Code="009";RecieptTable::Amount * 0.05;"0" ) but it is not coming up with the correct number.

Thank you.

• ###### 6. Re: Calculation

Howdy sweetcuda,

For multiple IF's, you'll have to do multiple IF statements by replacing our If;Then;Else with If;Then; (Else=If;Then;Else)

In other words, if true, do this...if not true, check if THIS true, do that...

If (CodeTable::Code="008";RecieptTable::Amount * 0.0842;   <-- this is the first IF

If (CodeTable::Code="009";RecieptTable::Amount * 0.05       <--- this is the second IF (also the first "else)

"0" ))     <--- This is the final "ELSE"

You can nest in many of these if needed.  There is also a "Case" function that does a very similar function as well.

Does this get you where you're going?

• ###### 7. Re: Calculation
Outstanding, that worked perfectly. Do you have a suggestion on a good book to use to learn how do to this type of coding or script writing?
• ###### 8. Re: Calculation

If you can find a library or bookstore that has books old enough, I find that some of the best conceptual references tend to be BASIC or FORTRAN reference books from the '70s and '80s.

Scripts (to my eyes anyway) are little FORTRAN programs that run in the background.  Mac folks may say the same thing whilst switching in the word "Applescript" for FORTRAN.

For actual current resources, I'll let someone else on the forum give guidance...I'm a self-taught muddler so I'm not familiar with the best current resources.