Results 1 to 9 of 9
  1. #1
    DanielleN is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    5

    How to make a table with age distribution per service per month

    Hi all,

    I am struggling with access and can't seem to find a proper solution to my problem.
    I have a patient database. In here you can find, among others, the date of birth of the patient, the date that the patient was treated, the service provided (you can choose physio, rehab or ortho).

    So what I would like is to create a cross table showing the service provided for age groups per month. It should look something like this
    On top in the columns the months: jan feb mar etc.

    Physio 0-4
    5-19
    20 and up
    Rehab 0-4
    5-19
    20 and up

    I was able to make the cross tabs by month and service but i have no clue how to do the age distribution. I did manage to calculate the age though.
    Can someone please help me out on how to make the age distributions and to get a table as shown in my example?



    Kind regards, Danielle

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    you'll need to use a nested iif or choose function

    iif(age <=4,"0-4",iif(age <=19,"5-19","20 and up"))

    or

    choose(age <=4,"0-4",age <=19,"5-19",true,"20 and up"))

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    @Ajax
    I was unaware of the Choose function and it piqued my interest. When I looked at MSDN, I was unable to understand the syntax you provided. I am understanding the function to behave more like an enumeration and less like a ternary.
    https://msdn.microsoft.com/en-us/lib.../gg264716.aspx

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    Ah yes - you are right - I meant the switch function. As you say choose is based on an incremental value

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Thanks for explaining, Ajax.

  6. #6
    DanielleN is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    5
    Something really strange is happening in my access.. I tried both your suggestions and they are not working. I now have this:
    Agedistribution: Switch([Age]<=4,"0-4",[Age]<=19,"5-19",[Age]>19,"20 and up")

    But the computer says the syntax of the expression is not valid, highlighting the "0-4".
    I use access 2016.

    If i open the same document on my work computer (access 2010) it works perfectly.

    Any idea what is going on?

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    Any idea what is going on?
    Nope - syntax looks fine to me. I'm assuming that if you are using a crosstab or groupby query that Age is a field and not a calculated value. If it is a calculated value then you need to substitute [Age] with the calculation, although the error you would have had would not have been a syntax error.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  9. #9
    DanielleN is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    5
    Thank you all for helping me. Ended up doing all me age distributions using the switch function in Access 2010 and later opening it in access 2016 and (strangely enough) this works.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculate Time in Service (year, month, day)
    By Randell in forum Programming
    Replies: 2
    Last Post: 07-30-2015, 05:49 PM
  2. Replies: 2
    Last Post: 02-17-2015, 01:01 PM
  3. Replies: 3
    Last Post: 12-29-2014, 10:14 AM
  4. Replies: 5
    Last Post: 11-25-2012, 03:21 PM
  5. Replies: 2
    Last Post: 10-27-2009, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums