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

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
 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.
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,874 Points 50k badge 2x thumb
Can you say in words what the 6 ranges are?
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb

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.

Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,874 Points 50k badge 2x thumb
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+")
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb
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!
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb
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!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,874 Points 50k badge 2x thumb
Formula variables are wonderful ways to make formulas more readable and easier to maintain.
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb
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.
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb

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.

Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb

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")

Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,874 Points 50k badge 2x thumb
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.
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb
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?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,874 Points 50k badge 2x thumb
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.
Photo of Richard

Richard

  • 260 Points 250 badge 2x thumb
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)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,874 Points 50k badge 2x thumb
You were close

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

Richard

  • 260 Points 250 badge 2x thumb
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.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,874 Points 50k badge 2x thumb
Great to hear.  It gets easier the more you play with the product!
(Edited)