5 Replies Latest reply on Dec 4, 2013 9:30 AM by philmodjunk

# Function to replicate Product ()

### Title

Function to replicate Product ()

### Post

I can't find a function for FM that I use a lot in spreadsheets called "Product ()."

It finds the product of up to 30 parameters; one of which is required.

It is a special case of the FM Evalutate() function.

Evaluate works great, but not on separate fields (that I can figure out.)

Am I missing something again? It seems strange that this isn't a standard FM function.

• ###### 1. Re: Function to replicate Product ()
Can't you just multiply all your numbers together instead of using a function?
• ###### 2. Re: Function to replicate Product ()

The UI allows the user to input fractions as text such as "1/4", "79/520" and "1/2".

Evaluate works if I allow the user to put all input into one text field with the operator:

"1/4 * 79/520 * 1/2"

But the user has to remember to put those operands in there.

So, I put this custom function together, but I just didn't know if someone had done something better.

EDIT: Found these at Brian Dunning (link). Not quite what I was looking for, but interesting.

•           Fraction ( _a_b ; _operator ; _c_d )
•
•           ListOperation ( list ; operator )
•
•           Operate ( Expression )

Function Product ( a ; b ; c ; d ; e ; f ; g ; h ; i )

If ( a ; Evaluate ( a ) ; 1 ) * // change to whatever operator you desire
If ( b ; Evaluate ( b ) ; 1 ) *
If ( c ; Evaluate ( c ) ; 1 ) *
If ( d ; Evaluate ( d ) ; 1 ) *
If ( e ; Evaluate ( e ) ; 1 ) *
If ( f ; Evaluate ( f ) ; 1 ) *
If ( g ; Evaluate ( g ) ; 1 ) *
If ( h ; Evaluate ( h ) ; 1 ) *
If ( i ; Evaluate ( i ) ; 1 )

EDIT:  Simplified logic in If().

• ###### 3. Re: Function to replicate Product ()

or you could do this:

Evaluate ( Substitute ( List ( a ; b ; c ; d ; e ; f ; g ; h ; i ) ; ¶ ; " * " ) )

• ###### 4. Re: Function to replicate Product ()

Phil, I expected some sort of recursive operation from you!   I doubt it would be quicker enough to make a difference.

I originally was going to use repetitions, but was discouraged due to only having up to 10 fixed fields for the factors. (Mini spreadsheet.)

Thanks! That does simplify it quite a bit and makes the operator a parameter to boot.

I'll have to rename the function ...

PS. Actually it is important to filter out the zero in a multiplication, but that can be done easily at the field level.

• ###### 5. Re: Function to replicate Product ()

There actually isn't any recursion here as I understand the term.

While a zero in one of these fields would produce a zero result, please be aware that a blank field will not produce such a result.

And if this were my system, I'd replace this set of fields with a set of related records in a related table.