COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Age range calculation problem

• Email
• Follow

```I'm recording "date of birth", and calculating "age" (unstored).  (The
calculation of age is working fine.)  I then need to calculate a further
field value, i.e. "age range".  I'm trying to set this field to "1" if the
person is aged 16-18, "2" if they're 19-24, etc.

The calculation I've used is:

If(age>15<19,1,(If(age>18<25,2,[etc...]))) - but it's not working.  (Age
range for all records is calculated as "1").

So my question is 2-fold:

1) Is there (and I suspect there is) a more elegant way to do this?
2) If this is a good enough way to do this, what have I done wrong in the
calculation?

Thanks in anticipation,

Dave Hobson.

So my

```
 0

See related articles to this posting

```Everyone in your group has an age > 15, therefore the If statement is
returning true for the first test and returning "1". Work in the other
direction.

Also, look into using the Case() or Choose() functions for jobs like
this, nested IF's will get ugly fairly fast.

Michael Myett

Dave Hobson wrote:
> I'm recording "date of birth", and calculating "age" (unstored).  (The
> calculation of age is working fine.)  I then need to calculate a further
> field value, i.e. "age range".  I'm trying to set this field to "1" if the
> person is aged 16-18, "2" if they're 19-24, etc.
>
> The calculation I've used is:
>
> If(age>15<19,1,(If(age>18<25,2,[etc...]))) - but it's not working.  (Age
> range for all records is calculated as "1").
>
> So my question is 2-fold:
>
> 1) Is there (and I suspect there is) a more elegant way to do this?
> 2) If this is a good enough way to do this, what have I done wrong in the
> calculation?
>
> Thanks in anticipation,
>
> Dave Hobson.
>
> So my
>
>
```
 0

```"Dave Hobson" <dave_hobson99@remove.yahoo.co.uk> wrote in message
news:eyCAc.107345\$wd7.74120@front-1.news.blueyonder.co.uk...
> I'm recording "date of birth", and calculating "age" (unstored).  (The
> calculation of age is working fine.)  I then need to calculate a further
> field value, i.e. "age range".  I'm trying to set this field to "1" if the
> person is aged 16-18, "2" if they're 19-24, etc.
>
> The calculation I've used is:
>
> If(age>15<19,1,(If(age>18<25,2,[etc...]))) - but it's not working.  (Age
> range for all records is calculated as "1").
>
> So my question is 2-fold:
>
> 1) Is there (and I suspect there is) a more elegant way to do this?
> 2) If this is a good enough way to do this, what have I done wrong in the
> calculation?
>
> Thanks in anticipation,
>
> Dave Hobson.
>
> So my
>
>

Use the Case function (as previously mentioned).

Case( age > 100, 5, age > 50, 4, age > 30, 3, age > 18, 2, 1)

```
 0

```"Glenn Schwandt" <schwandtg-at@aol-dot.com> wrote in message news:<10d6645fom83obf@corp.supernews.com>...
> "Dave Hobson" <dave_hobson99@remove.yahoo.co.uk> wrote in message
> news:eyCAc.107345\$wd7.74120@front-1.news.blueyonder.co.uk...
> > I'm recording "date of birth", and calculating "age" (unstored).  (The
> > calculation of age is working fine.)  I then need to calculate a further
> > field value, i.e. "age range".  I'm trying to set this field to "1" if the
> > person is aged 16-18, "2" if they're 19-24, etc.
> >
> > The calculation I've used is:
> >
> > If(age>15<19,1,(If(age>18<25,2,[etc...]))) - but it's not working.  (Age
> > range for all records is calculated as "1").
> >
> > So my question is 2-fold:
> >
> > 1) Is there (and I suspect there is) a more elegant way to do this?
> > 2) If this is a good enough way to do this, what have I done wrong in the
> > calculation?
> >
> > Thanks in anticipation,
> >
> > Dave Hobson.
> >
> > So my
> >
> >
>
> Use the Case function (as previously mentioned).
>
> Case( age > 100, 5, age > 50, 4, age > 30, 3, age > 18, 2, 1)

Glenn and Michael - thanks a lot for your help.
Dave.
```
 0

```In article <eyCAc.107345\$wd7.74120@front-1.news.blueyonder.co.uk>,
"Dave Hobson" <dave_hobson99@remove.yahoo.co.uk> wrote:

> I'm recording "date of birth", and calculating "age" (unstored).  (The
> calculation of age is working fine.)  I then need to calculate a further
> field value, i.e. "age range".  I'm trying to set this field to "1" if the
> person is aged 16-18, "2" if they're 19-24, etc.
>
> The calculation I've used is:
>
> If(age>15<19,1,(If(age>18<25,2,[etc...]))) - but it's not working.  (Age
> range for all records is calculated as "1").
>
> So my question is 2-fold:
>
> 1) Is there (and I suspect there is) a more elegant way to do this?
> 2) If this is a good enough way to do this, what have I done wrong in the
> calculation?
>
> Thanks in anticipation,
>
> Dave Hobson.

statment, which performs the same function, but is much tidier and
easier to use / read then multiple nested If statements.

BUT,
there is also a rather major problem in the way you've written the
tests within the If statement which may trip you up in future scripts /
calculations.

You've got all the tests written as "age>15<19". This will never give
the result you're expecting. "age > 15 < 19" is not a proper test (and
"15 < age < 19" wouldn't be either). This basically does a multiple
two-tests-in-one which is more easily readable by putting brackets in
as "(age > 15) < 19".

Now the first part (age > 15) will obviously return 'True' for anyone
over 15 and 'False' for those under 15. But tests in FileMaker and most
programming languages return these True/False answers as Boolean digits
where True = 1 and False = 0.

This then means that after the first test has been calculated your
second part of the multi-test becomes either "1 < 19" or "0 < 19",
which is obviously ALWAYS true.

Therefore no matter what age the person actually is you will ALWAYS a
True response from this multi-test and end up with the If statement
returning a result of "1".

To actually test if a value is between two figures you need to perform
two separate tests using the AND function, ie. (age > 15) and (age <
19). This would make your original If statement something along the
lines of:

If( (age>15) and (age<19), 1, If ( (age>18) and (age<25), 2, ...)

the highest possible value and work down, ie.

If (age>100, 9, If (age>90, 8, ...)

that way you only need to test the lower limit since the upper limit
was tested in the preceeding If statement, and it will return the
result for the first test that succeeds. This becomes easier to see
with the Case statement that removes all those extra If's.

Hopefully helping harassed humans happily handle handiwork hardships  ;o)
```
 0

```Thanks very much for this ample explanation of the multiple errors of my
ways!  As ever, I'm amazed at the non-judgmental manner in which experts in
this group respond to beginners.

Thanks again.

Dave.

> In article <eyCAc.107345\$wd7.74120@front-1.news.blueyonder.co.uk>,
> "Dave Hobson" <dave_hobson99@remove.yahoo.co.uk> wrote:
>
> > I'm recording "date of birth", and calculating "age" (unstored).  (The
> > calculation of age is working fine.)  I then need to calculate a further
> > field value, i.e. "age range".  I'm trying to set this field to "1" if
the
> > person is aged 16-18, "2" if they're 19-24, etc.
> >
> > The calculation I've used is:
> >
> > If(age>15<19,1,(If(age>18<25,2,[etc...]))) - but it's not working.  (Age
> > range for all records is calculated as "1").
> >
> > So my question is 2-fold:
> >
> > 1) Is there (and I suspect there is) a more elegant way to do this?
> > 2) If this is a good enough way to do this, what have I done wrong in
the
> > calculation?
> >
> > Thanks in anticipation,
> >
> > Dave Hobson.
>
> statment, which performs the same function, but is much tidier and
> easier to use / read then multiple nested If statements.
>
>
> BUT,
> there is also a rather major problem in the way you've written the
> tests within the If statement which may trip you up in future scripts /
> calculations.
>
> You've got all the tests written as "age>15<19". This will never give
> the result you're expecting. "age > 15 < 19" is not a proper test (and
> "15 < age < 19" wouldn't be either). This basically does a multiple
> two-tests-in-one which is more easily readable by putting brackets in
> as "(age > 15) < 19".
>
> Now the first part (age > 15) will obviously return 'True' for anyone
> over 15 and 'False' for those under 15. But tests in FileMaker and most
> programming languages return these True/False answers as Boolean digits
> where True = 1 and False = 0.
>
> This then means that after the first test has been calculated your
> second part of the multi-test becomes either "1 < 19" or "0 < 19",
> which is obviously ALWAYS true.
>
> Therefore no matter what age the person actually is you will ALWAYS a
> True response from this multi-test and end up with the If statement
> returning a result of "1".
>
>
> To actually test if a value is between two figures you need to perform
> two separate tests using the AND function, ie. (age > 15) and (age <
> 19). This would make your original If statement something along the
> lines of:
>
>    If( (age>15) and (age<19), 1, If ( (age>18) and (age<25), 2, ...)
>
>
> the highest possible value and work down, ie.
>
>    If (age>100, 9, If (age>90, 8, ...)
>
> that way you only need to test the lower limit since the upper limit
> was tested in the preceeding If statement, and it will return the
> result for the first test that succeeds. This becomes easier to see
> with the Case statement that removes all those extra If's.
>
>
>
> Hopefully helping harassed humans happily handle handiwork hardships  ;o)

```
 0

5 Replies
499 Views

Similar Articles

12/20/2013 1:54:27 PM
page loaded in 83346 ms. (0)

Similar Artilces:

calculating age
Friday afternoon question: How do people usually calculate age? For example, I have date of birth (dbirth) and date when a blood sample was taken (DateTaken), both as SAS dates. Two methods I commonly use are: age1=(DateTaken-dbirth)/365.25; age2= (year(DateTaken)-year(dbirth)-1) +(month(DateTaken) > month(dbirth)) +(month(DateTaken)=month(dbirth))*(day(DateTaken) ge day(dbirth)); The first is simple (and sometime I take INT(age1)). The second is what I call 'age in birthdays' --- it is what a person what say their age was, if ask. (Yes, I realise there is a problem i...

Problem with calculations...........
Hi all, I've been trying to add the following values in a form, but I don't know how to do it: Start Stop WorkedHours SET UET Other Time TotalHours 08:00PM 04:00PM 8:00 05:00 08:00 The DataType of these fields are: Start: Date/time Stop: Date/time WorkedHours: TEXT SET,UET,OtherTime,TotalHours: TEXT The problem is that when the employee enter, for instance, in the SET field: 05:00. I want this field to add up to Totalhours,the same thing with UET,Other Time.. I tried to change the datatype of these fields to Date/Time, but when I...

Age Calculation
I have a FMP database that keeps track of driver education students. I'm not knowledgeable in FMP, but I can usually get it to do what I want. Which one of these formulas would work best to calculate age based on birth date and the system date or is there a better one? I'm using the second one Year(Today) - Year(Birthdate) - If(Today< Date(Month(Birthdate), Day(Birthdate),Year(Today)),1,0) Year(Status(CurrentDate)) - Year(Birthdate) - If(Status(CurrentDate)< Date(Month(Birthdate), Day(Birthdate),Year(Status(CurrentDate))),1,0) I'm also having trouble with the age not rec...

Range Problem
I have made 2 fields of of ranges reporting : one for month,the other for the year . My report printing correctly from the inner year The range Month from : 1 year : 2004 Month to : 9 year : 2004 My condition is print if month_field <= month_year .and. year == year_screen How can I handle monthes between 2 years Month from : 9 year : 2003 Month to : 6 year : 2004 hi > How can I handle monthes between 2 years > > Month from : 9 year : 2003 > Month to : 6 year : 2004 build a Index on cYEA...

Problem with calculation
I have a machine with parameters and want an end result of a dollar amount. I have made adjustments over and over but cannot get the anything but 0 in the field. Any idea why? Materials2 is definitely "PO". These are tolerances for a machine. It should read: If materials2 equals "PO" then gauge between .625 and .655 is 1.5 if gauge is between Case (( materials2="PO"); (ga_min_tol � .625 and ga_max_tol � .655 ); 1.5; ( ga_min_tol � .467 and ga_max_tol � .5 ); 1.15; ( ga_min_tol � .36 and ga_max_tol � .187 ); 1; ( ga_min_tol � .156 and ga_max_tol � .1...

calculation problem!
In my program there are several calculations. The dates are from a curve (picture in the attachement) and with the dates from the data i want to make&nbsp; a bendingstrenght-calculation. When&nbsp;i type random numbers( for example x=(10,20,30,40,50,60,70), y=(0,5;0,6;0,7;0,8;0,7;0,6;0,5) like a curve) and start the program, the resulting numbers&nbsp;are false. Could somebody check my calculation, please?! TNKS &nbsp; Best regards, &nbsp; Peter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Calculation Information: *************************** A=(MG*(ML - XL)) / ML ...

Problems with range
Hey to everybody, im just beginning to program in python. So i was trying some function but always when i try the range function i get a error message. for number in range(1,100): print number Error---> There's an error in your program: expected an indented block I tried many examples i found at different tutorials but i always get the error. On Fri, 25 Jun 2004 19:06:39 -0400, Adrian Albisser <justblame@123.cl> wrote: > Hey to everybody, im just beginning to program in python. So i was trying > some function but always when i try the range function i g...

problem in calculation !
1 - 2.3 + 1.72 - 0.42 result is not zero !...how come ....it's really important to be calculated right because it's included in if condition and it messes every thing up ....thanks for ur help in advance :) "mohammed " <m.eng.mahrous@gmail.com> wrote in message <hqmrqt\$o96\$1@fred.mathworks.com>... > 1 - 2.3 + 1.72 - 0.42 > result is not zero !...how come ....it's really important to be calculated right because it's included in if condition and it messes every thing up ....thanks for ur help in advance :) Hi Mohammed, how about using floor(...

range calculation
i ve a The Cisco Aironet 1200 Series(2.4 ghz) and my antenna is 12 dbi omni i want to buy amplifier 1 watt and 16 dbi amp2440 or amp2441 how can i calculate the extend area i mean how much km extend ?? (the formula"?) In article <b3d17a03.0501270449.224efdb@posting.google.com>, herodot <herodot@diplomats.com> wrote: :i ve a The Cisco Aironet 1200 Series(2.4 ghz) and my antenna is 12 dbi :omni i want to buy amplifier 1 watt and 16 dbi amp2440 or amp2441 how :can i calculate the extend area i mean how much km extend ?? If you want to be able to extend to kilometers, then ins...

Range Coder Problem
Hi I'm having a problem with Mr.Dmitry Subbotin range coder class. I know (not much) about range coding but I failed to understand this "somewhat" simple class. Can someone give me a simple explanation of how to use this class. Here's my statistical model, the word to encode is COMPRESSION : struct { char c; unsigned short int low; unsigned short int high; } probabilities[] = {{ 'C', 0, 1 }, { 'O', 1, 3 }, { 'M', 3,...