Results 1 to 8 of 8
  1. #1
    chosenonee is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    10

    Help with calculations

    Hello, I'm using this to calculate totals in an Access 10 db query:



    Sum(IIf([sex]="MALE" And [Diag]="200",1,0))+Sum(IIf([DiagII]="200",1,0))+Sum(IIf([DiagIII]="200",1,0))+Sum(IIf([DiagIV]="200",1,0))+Sum(IIf([DiagV]="200",1,0))

    That's a copy of one of many similar but it's adding an additional number to the total and I can't figure out what is wrong with it>

    Thanks for the help.

    Don

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Hard to tell without seeing the data. You realize that the "Male" test is only applied to the Diag test? Also, your design is suspect with the numbered fields. It likely isn't normalized:

    Fundamentals of Relational Database Design -- r937.com
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,837
    you could try

    Sum(ABS([sex]="MALE" And [Diag]="200")+ABS([DiagII]="200")+ABS([DiagIII]="200")+ABS([DiagIV]="200")+ABS([DiagV]="200"))

    Also - I presume your diag fields are all text and not numeric?
    Last edited by CJ_London; 01-06-2016 at 06:50 PM. Reason: another question

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    In addition to what Paul and Ajax posted, could you tell us in plain English WHAT you are trying to do?

  5. #5
    chosenonee is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    10
    Thank you all for chiming in. the purpose is to get a total of the number of "Males" with a 200 diagnosis. I have the same for Females. The "Diag" tables 1-5 are text and they are combo box (Value Lists). Not sure if that makes a difference. I looked briefly at the Relational Database Design from Paul and I see some things I did wrong in creating this massive database but I need a quick fix now as reports are due and we are depending on the database for the information. I tried the suggestion from Ajax, thank you but that didn't work at all. I'd appreciate any other ideas.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Each of your tests has to include the "Male" test, or perhaps:

    Sum(IIf([sex]="MALE" And ([Diag]="200" OR [DiagII]="200" OR [DiagIII]="200" OR [DiagIV]="200" OR [DiagV]="200"),1,0))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    chosenonee is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    10
    Thanks pbaldy, that fixed my problem. Thank you all tremendously. I'm sure I'll be back with more questions and looking to learn more.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 30
    Last Post: 09-30-2015, 10:58 AM
  2. calculations
    By frustratedwithaccess in forum Queries
    Replies: 5
    Last Post: 01-08-2015, 01:56 PM
  3. Calculations in a query
    By dichotomous2013 in forum Access
    Replies: 4
    Last Post: 02-19-2013, 06:55 AM
  4. calculations
    By DariusD in forum Access
    Replies: 3
    Last Post: 01-01-2013, 07:22 PM
  5. calculations??
    By richrit in forum Access
    Replies: 1
    Last Post: 04-11-2012, 05:06 PM

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