### 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!

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