dbTalk Databases Forums  

A more elegant calculation

comp.databases.filemaker comp.databases.filemaker


Discuss A more elegant calculation in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
CRC123
 
Posts: n/a

Default A more elegant calculation - 04-29-2007 , 10:27 AM






FMP 8, Mac OSX

I have 6 fields that are each results of a series of calculations.
Call them A, B,C, D, E, and F.

Any one or more may result in a product of 0 [ie: (a +b) * y * 0 = 0]
so IsEmpty isn't an option in the calculation.

I am a bit of a newbie at the more sophisticated functions such as
"Count" and "Get.." Without typing in 36 Case/Results for all the
possible configurations, is there an elegant way of calculating the
average of just the non-zero fields?

Thanks


Reply With Quote
  #2  
Old   
Helpful Harry
 
Posts: n/a

Default Re: A more elegant calculation - 04-29-2007 , 04:06 PM






In article <1177860435.785691.240210 (AT) o5g2000hsb (DOT) googlegroups.com>,
CRC123 <swanson (AT) windsongappraisals (DOT) com> wrote:

Quote:
FMP 8, Mac OSX

I have 6 fields that are each results of a series of calculations.
Call them A, B,C, D, E, and F.

Any one or more may result in a product of 0 [ie: (a +b) * y * 0 = 0]
so IsEmpty isn't an option in the calculation.

I am a bit of a newbie at the more sophisticated functions such as
"Count" and "Get.." Without typing in 36 Case/Results for all the
possible configurations, is there an elegant way of calculating the
average of just the non-zero fields?

Thanks
IsEmpty and Count aren't going to work since a value of 0 is not an
empty field. The Get functions are of no use at all - they're mostly
used to convert numbers to Text or vice-versa and obtain system stats
(eg. Get(CurrentRecordNum) to obtain the current record' internal ID
number).

You also shouldn't need "36 Case / Results" - since you've only got six
fields, at most you'll need six.

Assuming you actually want the Average of just the non-zero fields,
then something like this would work:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - If (A = 0, 1, 0)
- If (B = 0, 1, 0)
- If (C = 0, 1, 0)
- If (D = 0, 1, 0)
- If (E = 0, 1, 0)
- If (F = 0, 1, 0)
)

You can use Case instead of If, if you really want to - it makes no
difference when there's only one test-result being performed.


Or the "more elegant" solution of:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - (A = 0) - (B = 0) - (C = 0) - (D = 0) - (E = 0) - (F = 0))

This uses Boolean logic, where the tests "A = 0" are evaluated the same
way as the full If statements, ie 1 for true and 0 for false. When any
of the field contains 0 that field is subtracted from the total of 6
used to evaluate the Average.



Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #3  
Old   
d-42
 
Posts: n/a

Default Re: A more elegant calculation - 04-29-2007 , 05:20 PM



On Apr 29, 2:06 pm, Helpful Harry <helpful_ha... (AT) nom (DOT) de.plume.com>
wrote:
Quote:
In article <1177860435.785691.240... (AT) o5g2000hsb (DOT) googlegroups.com>,

CRC123 <swan... (AT) windsongappraisals (DOT) com> wrote:
FMP 8, Mac OSX

I have 6 fields that are each results of a series of calculations.
Call them A, B,C, D, E, and F.

Any one or more may result in a product of 0 [ie: (a +b) * y * 0 = 0]
so IsEmpty isn't an option in the calculation.

I am a bit of a newbie at the more sophisticated functions such as
"Count" and "Get.." Without typing in 36 Case/Results for all the
possible configurations, is there an elegant way of calculating the
average of just the non-zero fields?

Thanks

IsEmpty and Count aren't going to work since a value of 0 is not an
empty field. The Get functions are of no use at all - they're mostly
used to convert numbers to Text or vice-versa and obtain system stats
(eg. Get(CurrentRecordNum) to obtain the current record' internal ID
number).

You also shouldn't need "36 Case / Results" - since you've only got six
fields, at most you'll need six.

Assuming you actually want the Average of just the non-zero fields,
then something like this would work:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - If (A = 0, 1, 0)
- If (B = 0, 1, 0)
- If (C = 0, 1, 0)
- If (D = 0, 1, 0)
- If (E = 0, 1, 0)
- If (F = 0, 1, 0)
)

You can use Case instead of If, if you really want to - it makes no
difference when there's only one test-result being performed.

Or the "more elegant" solution of:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - (A = 0) - (B = 0) - (C = 0) - (D = 0) - (E = 0) - (F = 0))

This uses Boolean logic, where the tests "A = 0" are evaluated the same
way as the full If statements, ie 1 for true and 0 for false. When any
of the field contains 0 that field is subtracted from the total of 6
used to evaluate the Average.

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)
Nice calc Harry.

Here's another approach
define a custom function: sumlist L

if (valuescount(L) = 1;
L;
middlevalues(L,1,1) + sumlist (middlevalues(L, 2, valuecount(L)-1))

then you can compute non-zero average as follows:
let (nonzerocount = valuecount(filtervalues(L,"0P");
if ( nonzerocount = 0;
'divide by zero error';
sumlist(L) / nonzerocount))

where L is a list of values. (and "P" is the paragraph marker)
you can define the second part as a custom func, or not.

The main advantage is that it works on an arbitrary number of values,
instead of being limited to 5. The main disadvantages are of course,
you need FM Advanced to defien a custom function (which you need
because the summation is recursive), and of course, you have to get
the values into a list before computing the result, which means
concatenating them together separated by "P"s

Given how much FM requires you to build and disect value lists, and
the support it provides with the various "MiddleValues", "ValueCount",
etc functions, its pretty (scratch that REALLY) annoying they haven't
provided a "Values(v1, {v2...vn})" function to build them for us on
the fly without the ugly text concatenation syntax. (Don't tell me
they added it in 8.5...)

Note also that you can do some nifty stuff with value lists (ie the
ones you define for drop down lists/popup menues) to generate the
value lists you need, since you can access those value lists via
script steps. If you need long or complex lists, defined via
relationships, that can be neat trick to generate them.

Note also that sumlist is pretty inefficient; there are some tricks
you can do to make it much faster. (but only relevant if you are
potentially dealing with LONG lists, in the hundreds, or thousands.)

Overall, if you just need the 6 fields, I'd stick with Harry's
solution; its straightforward and more efficient; I just put this out
there to show how one might approach it if you needed to handle a more
generic / larger problem.\

-cheers,
Dave



Reply With Quote
  #4  
Old   
Tom Stiller
 
Posts: n/a

Default Re: A more elegant calculation - 04-29-2007 , 05:29 PM



In article <300420070906259959%helpful_harry (AT) nom (DOT) de.plume.com>,
Helpful Harry <helpful_harry (AT) nom (DOT) de.plume.com> wrote:

Quote:
n article <1177860435.785691.240210 (AT) o5g2000hsb (DOT) googlegroups.com>,
CRC123 <swanson (AT) windsongappraisals (DOT) com> wrote:

FMP 8, Mac OSX

I have 6 fields that are each results of a series of calculations.
Call them A, B,C, D, E, and F.

Any one or more may result in a product of 0 [ie: (a +b) * y * 0 = 0]
so IsEmpty isn't an option in the calculation.

I am a bit of a newbie at the more sophisticated functions such as
"Count" and "Get.." Without typing in 36 Case/Results for all the
possible configurations, is there an elegant way of calculating the
average of just the non-zero fields?

Thanks

IsEmpty and Count aren't going to work since a value of 0 is not an
empty field. The Get functions are of no use at all - they're mostly
used to convert numbers to Text or vice-versa and obtain system stats
(eg. Get(CurrentRecordNum) to obtain the current record' internal ID
number).
Doesn't
SUM(A1:A6)/COUNTIF(A1:A6,"<>0")
do the job?

--
Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3
7BDA 71ED 6496 99C0 C7CF


Reply With Quote
  #5  
Old   
Tom Stiller
 
Posts: n/a

Default Re: A more elegant calculation - 04-29-2007 , 05:32 PM



In article <tomstiller-F6130E.18293529042007 (AT) comcast (DOT) dca.giganews.com>,
Tom Stiller <tomstiller (AT) comcast (DOT) net> wrote:

Quote:
In article <300420070906259959%helpful_harry (AT) nom (DOT) de.plume.com>,
Helpful Harry <helpful_harry (AT) nom (DOT) de.plume.com> wrote:

n article <1177860435.785691.240210 (AT) o5g2000hsb (DOT) googlegroups.com>,
CRC123 <swanson (AT) windsongappraisals (DOT) com> wrote:

FMP 8, Mac OSX

I have 6 fields that are each results of a series of calculations.
Call them A, B,C, D, E, and F.

Any one or more may result in a product of 0 [ie: (a +b) * y * 0 = 0]
so IsEmpty isn't an option in the calculation.

I am a bit of a newbie at the more sophisticated functions such as
"Count" and "Get.." Without typing in 36 Case/Results for all the
possible configurations, is there an elegant way of calculating the
average of just the non-zero fields?

Thanks

IsEmpty and Count aren't going to work since a value of 0 is not an
empty field. The Get functions are of no use at all - they're mostly
used to convert numbers to Text or vice-versa and obtain system stats
(eg. Get(CurrentRecordNum) to obtain the current record' internal ID
number).

Doesn't
SUM(A1:A6)/COUNTIF(A1:A6,"<>0")
do the job?
Oops, maybe I'd better pay more attention to the group I'm responding to.

--
Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3
7BDA 71ED 6496 99C0 C7CF


Reply With Quote
  #6  
Old   
CRC123
 
Posts: n/a

Default Re: A more elegant calculation - 04-29-2007 , 05:59 PM



On Apr 29, 2:06 pm, Helpful Harry <helpful_ha... (AT) nom (DOT) de.plume.com>
wrote:
Quote:
In article <1177860435.785691.240... (AT) o5g2000hsb (DOT) googlegroups.com>,

CRC123 <swan... (AT) windsongappraisals (DOT) com> wrote:
FMP 8, Mac OSX

I have 6 fields that are each results of a series of calculations.
Call them A, B,C, D, E, and F.

Any one or more may result in a product of 0 [ie: (a +b) * y * 0 = 0]
so IsEmpty isn't an option in the calculation.

I am a bit of a newbie at the more sophisticated functions such as
"Count" and "Get.." Without typing in 36 Case/Results for all the
possible configurations, is there an elegant way of calculating the
average of just the non-zero fields?

Thanks

IsEmpty and Count aren't going to work since a value of 0 is not an
empty field. The Get functions are of no use at all - they're mostly
used to convert numbers to Text or vice-versa and obtain system stats
(eg. Get(CurrentRecordNum) to obtain the current record' internal ID
number).

You also shouldn't need "36 Case / Results" - since you've only got six
fields, at most you'll need six.

Assuming you actually want the Average of just the non-zero fields,
then something like this would work:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - If (A = 0, 1, 0)
- If (B = 0, 1, 0)
- If (C = 0, 1, 0)
- If (D = 0, 1, 0)
- If (E = 0, 1, 0)
- If (F = 0, 1, 0)
)

You can use Case instead of If, if you really want to - it makes no
difference when there's only one test-result being performed.

Or the "more elegant" solution of:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - (A = 0) - (B = 0) - (C = 0) - (D = 0) - (E = 0) - (F = 0))

This uses Boolean logic, where the tests "A = 0" are evaluated the same
way as the full If statements, ie 1 for true and 0 for false. When any
of the field contains 0 that field is subtracted from the total of 6
used to evaluate the Average.

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)
Tres elegant indeed!
I shall whip it right up and keep you posted.
Many Thanks.



Reply With Quote
  #7  
Old   
CRC123
 
Posts: n/a

Default Re: A more elegant calculation - 04-29-2007 , 06:31 PM



On Apr 29, 3:59 pm, CRC123 <swan... (AT) windsongappraisals (DOT) com> wrote:
Quote:
On Apr 29, 2:06 pm, Helpful Harry <helpful_ha... (AT) nom (DOT) de.plume.com
wrote:



In article <1177860435.785691.240... (AT) o5g2000hsb (DOT) googlegroups.com>,

CRC123 <swan... (AT) windsongappraisals (DOT) com> wrote:
FMP 8, Mac OSX

I have 6 fields that are each results of a series of calculations.
Call them A, B,C, D, E, and F.

Any one or more may result in a product of 0 [ie: (a +b) * y * 0 = 0]
so IsEmpty isn't an option in the calculation.

I am a bit of a newbie at the more sophisticated functions such as
"Count" and "Get.." Without typing in 36 Case/Results for all the
possible configurations, is there an elegant way of calculating the
average of just the non-zero fields?

Thanks

IsEmpty and Count aren't going to work since a value of 0 is not an
empty field. The Get functions are of no use at all - they're mostly
used to convert numbers to Text or vice-versa and obtain system stats
(eg. Get(CurrentRecordNum) to obtain the current record' internal ID
number).

You also shouldn't need "36 Case / Results" - since you've only got six
fields, at most you'll need six.

Assuming you actually want the Average of just the non-zero fields,
then something like this would work:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - If (A = 0, 1, 0)
- If (B = 0, 1, 0)
- If (C = 0, 1, 0)
- If (D = 0, 1, 0)
- If (E = 0, 1, 0)
- If (F = 0, 1, 0)
)

You can use Case instead of If, if you really want to - it makes no
difference when there's only one test-result being performed.

Or the "more elegant" solution of:

NonZeroAverage Calculation, Number Result, Unstored
= (A + B + C + D + E + F)
/ (6 - (A = 0) - (B = 0) - (C = 0) - (D = 0) - (E = 0) - (F = 0))

This uses Boolean logic, where the tests "A = 0" are evaluated the same
way as the full If statements, ie 1 for true and 0 for false. When any
of the field contains 0 that field is subtracted from the total of 6
used to evaluate the Average.

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)

Tres elegant indeed!
I shall whip it right up and keep you posted.
Many Thanks.
Since my grandson isn't around to tell me. "GrannyDanny you sound
silly," May I say

PERFECTAMUNDO!
Thanks



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.