Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am designing a QV app using data that I loaded in QV from an excel spreadsheet. The spreadsheet lists individuals with their ages. I tried to create age groups in QV scripting using the age field and "if" statement but some of the individuals in the data were not assigned to any age group even though their age is included in the data both in QV and in the excel spreadsheet. How do I fix these missing age groups? could there be something wrong with the scripting? the script loaded fine.
LOAD *,
if([CMED Age] >20, 'Over 20',
if([CMED Age] <= 20 and [CMED Age] >= 16, '16 - 20',
if([CMED Age] <= 15 and [CMED Age] >= 11, '11 - 15',
if([CMED Age] <= 10 and [CMED Age] >= 6, '6 - 10',
if([CMED Age] <= 5 and [CMED Age] >= 4, '4 - 5',
if([CMED Age] <= 3 and [CMED Age] >= 1, '1 - 3',
if([CMED Age] < 1, 'Under 1'))))))) as [CMED Age_Group];
Thanks
floor (or round or ceil) the age
or change the limit
LOAD *,
if([CMED Age] >20, 'Over 20',
if([CMED Age] <= 20 and [CMED Age] > 15, '>15 - 20',
if([CMED Age] <= 15 and [CMED Age] > 10, '>10 - 15',
if([CMED Age] <= 10 and [CMED Age] > 5, '>5 - 10',
if([CMED Age] <= 5 and [CMED Age] > 3, '>3 - 5',
if([CMED Age] <= 3 and [CMED Age] >= 1, '1 - 3',
if([CMED Age] < 1, 'Under 1'
)))))))
as [CMED Age_Group];
Have you tried like this:
LOAD *,
if([CMED Age] >20, 'Over 20',
if([CMED Age] <= 20 and [CMED Age] >= 16, '16 - 20',
if([CMED Age] <= 15 and [CMED Age] >= 11, '11 - 15',
if([CMED Age] <= 10 and [CMED Age] >= 6, '6 - 10',
if([CMED Age] <= 5 and [CMED Age] >= 4, '4 - 5',
if([CMED Age] <= 3 and [CMED Age] >= 1, '1 - 3',
if([CMED Age] < 1, 'Under 1', 'Missing Group'))))))) as [CMED Age_Group];
But that would tell it to assume that the age group is missing for that individual right? which would be incorrect because the individual does have an age in the age field and so, should have an age group among those listed in the script, rather than being defined as "missing group". I can't seem to understand why some of the individuals were not grouped into one of the age groups listed - that's what I would like to fix...
Can you share the sample data if possible?
Also check possibility of using class function QV provides to create buckets like this.
Here's what the data looks like:
Name | DOB | Age (yrs) |
Name1 | 4/27/2012 | 3 |
Name2 | 8/24/2010 | 5 |
Name3 | 12/31/2007 | 8 |
Name4 | 1/14/2014 | 2 |
Name5 | 10/10/2007 | 8 |
Name6 | 11/22/2010 | 5 |
maybe you have decimal in some age?
10.5
15.5
That's just what I was thinking because the age field was a calculated field in excel using the date of birth. So, what's the best way to resolve that?
I noticed that the people that do not have an age group assigned have an age at either the lower or higher end of each age group
You can try to format it like that num(text(CMED_AGE))....