Skip to main content
Question

How do I include or exclude a person within a date range with just a person's birth date and today date?

  • May 24, 2017 8:13 PM UTC
  • 16 replies
  • 206 views

 I need to set this formula up over six potential date ranges that a person's record in the database could fall into. The only null condition I can think of is if a data entry person forgets to put the birthdate in the persons record during the intake process.
This topic has been closed for replies.

16 replies

Can you say in words what the 6 ranges are?

  • Author
  • Observing
  • May 24, 2017 8:20 PM UTC

Here's the ranges:

0-11

12-15

16-24

25-34

35-44

45-54

55 and over. That's a total of seven age categories. I missed the last one in the original count.


Try this are a formula text field 

var date DOB = [DOB]; // put your date of birth field here

var number AGE =
Year(Today())-Year($DOB)
-
If(
Month(Today())<Month($DOB)
or
(Month(Today())=Month($DOB) and Day(Today())<Day($DOB)),1,0);


IF(
isNull($DOB), "  Missing D.O.B.",
$AGE <= 11, " 0-11",
$AGE <= 15, "12-15,

etc

$AGE >=55, "55+")

  • Author
  • Observing
  • May 24, 2017 9:07 PM UTC
OK, I will give it a shot and let you know how it worked. Thanks so much. I would have never figured this out on my own!

  • Author
  • Observing
  • May 24, 2017 9:23 PM UTC
OK, it works! I never used a variable before. I think I learned something today, hopefully. Thanks for your help! I would have never of been able to get this without direction!

Formula variables are wonderful ways to make formulas more readable and easier to maintain.

  • Author
  • Observing
  • May 24, 2017 9:29 PM UTC
Yes, thanks to your input I just learned a valuable tool that I will try to apply as I chunk forward on my development. Again, thanks so much for your help.

  • Author
  • Observing
  • May 24, 2017 10:09 PM UTC

I am getting the formula to work somewhat. when I test it, I am getting incorrect results. I have tested the formula so far by:

  • Removing a date in the 'Date of Birth' to see if it returns the 'null' condition, "Missing D.O.B." which it does not.
  • There also seems to be something wrong with the age range '0-11' as it returns records that are over 11 years of age.


Any suggestions on how to fix? If making the field return just a '1' if the record is within the age range or a null or 0 if the record is in the age range is easier, that would be great as I need to just count those records in each age range anyhow.


  • Author
  • Observing
  • May 24, 2017 10:11 PM UTC

Forgot to give you the formula I used in the 0-11 age range field:


var date DOB = [Date of Birth];
var number AGE =
Year(Today())-Year($DOB)
-
If(Month(Today())<Month($DOB)
or
(Month(Today())=Month($DOB) and Day(Today())<Day($DOB)),1,0);
If(IsNull($DOB), "Missing D.O.B.",$AGE <=11, "0-11")


I'm not understanding why you would want to have separate fields for each date range result. It should just be one field.

When I get a chance tonight I will replicate the formula and test it, but it sure looks right to me.

  • Author
  • Observing
  • May 24, 2017 11:49 PM UTC
I have attached a jpg of the data requested in a monthly report that segregates the age categories needed for reporting. Maybe I am approaching this problem the wrong way??? Should this be done through the QB reports process?

OK, I f you want to easily create a report to look like that, yes I see why you would want to have separate fields.  You would want that to be a numeric formula field to calculate to a 1 or a 0.

var date DOB = [Date of Birth];

var number AGE =
Year(Today())-Year($DOB)
-
If(Month(Today())<Month($DOB)
or
(Month(Today())=Month($DOB) and Day(Today())<Day($DOB)),1,0);

If(IsNull($DOB), 0, $AGE <=11, 1,0)


I did test the formula I originally posted and it worked for me.  Contact me via the information in my profile if you would like some one on one assistance.

  • Author
  • Observing
  • May 25, 2017 4:40 PM UTC
I think I am getting it. Just a question on the ranges; For the next age range, '12-15' is the last formula this:     If(IsNull($DOB), 0, $AGE >11<=15, 1,0)

You were close

If(IsNull($DOB), 0,
$AGE >11 and $AGE<=15, 1,0)

  • Author
  • Observing
  • May 25, 2017 6:41 PM UTC
Thanks. I have added the fields based on each age category and tested it with various DOB's. It looks good. It's working! Thanks so much for your help. I am not sure I would have been able to get this one on my own.

Great to hear.  It gets easier the more you play with the product!