4 Replies Latest reply on Jun 1, 2011 8:10 AM by philmodjunk

# Question using "IF" in Calculation Field

### Title

Question using "IF" in Calculation Field

### Post

Hello,
I have some questions using "IF" in Calculation Field.
I'm a new FM user, and have some basic questions.

I need to calculate the following:
Let's say I sell apples, for example, in my store.
Sometimes I sell this item by piece, and sometimes I sell them by weight.

In my FM database, I have the following fields:
Number field: weight
Number field: quantity of pieces
Choice field: called "unit" with options "kilo" or "piece".
Number field: price
Calculation field: total to pay

If I sell the apples by weight, I inform to the Choice field "kilo", and the "total to pay" calculation field will calculate for me "weight" * "price".

If I sell the apples by piece, I inform to the Choice field "piece", and the "total to pay" calculation field will calculate for me "quantity of pieces" * "price".

How do I do this in FM? In Excel formula, this is what I use to do this:

=IF(price="";"";IF(unit="kg";(weight * price);IF(unit="pc";(quantity of pieces * price);0)))

It's possible to see the Form here (options by weight and by piece calculation) - these forms were for Bento, but now I'm updating to FM:
http://cl.ly/142e1g001e2Y0Z2P2m1b
http://cl.ly/1l0Z1X2h2q1P2X1d200M

Thanks a lot for the help!

• ###### 1. Re: Question using "IF" in Calculation Field

hi i am also new to fm, but try this

B_type = Killo or Qty (drop down menu)

Price_k = price for killo "field"

price_q =price for 1 p "field"

amou_killo = how many killos  "field"

amou_qty = how many qtys  " field"

create total "calculation" field. then you put, case ( B_type="killo": price_k*amou_killo; B_type="qty": price_q*amou_qty:0)

try that,

LH

• ###### 2. Re: Question using "IF" in Calculation Field

LH,
But this way is not good, because I'll have many more fields. And I cannot add more fields to my database.

• ###### 3. Re: Question using "IF" in Calculation Field

You've stated you cannot add more fields to your db.  I hope you can change the Calculaltion field???

If so, set it up as follows:

If ( Table::unit = "piece" ; Table::quantity of pieces * Table::price ; If ( Table::unit = "kilo" ; Table::weight * Table::price ; "" ) )

Simple If that says if the value of unit is "piece", then calc it out using quantity times price, else if unit is "kilo", then calc it out as weight times price, otherwise leave the field blank (the "" at the end).

hth

- shud

• ###### 4. Re: Question using "IF" in Calculation Field

Maicon Piovesan,

If you can define or redefine calculation fields, you can also add more fields to your database, but your last post suggests that you may have multiple fields where a related table of records would do better and also reduce the total number of fields defined in your table.