Results 1 to 7 of 7
  1. #1
    RogerC is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    4

    Sum IIf Multiple Criteria

    I want to create a calculated field in an Access report using the Sum IIf function with multiple conditions.



    When only one condition is used, the formula works just fine: =Sum(IIf([Balance]="ABC",[Amount],0))

    Similarly, I get the correct results when I plug in the other condition, =Sum(IIf([Balance]="XYZ",[Amount],0))

    But when I combine the two conditions with an Or function, nothing happens.
    =Sum(IIf([Balance]="ABC" Or [Balance]="XYZ",[Amount],0))

    Am I using the wrong syntax?
    Thanks in advance.
    Roger

  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,521
    The syntax looks fine to me. By nothing happens, you mean the textbox is blank? Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Looks right to me also. But if the control is in the detail section, I think (could be wrong ) you would use

    =IIf([Balance]="ABC" Or [Balance]="XYZ",[Amount],0)

    In the footer, use
    =SUM(Text32)

    where Text32 is the name of the control that has the IIF() expression.


    Or you could try

    =IIf([Balance]="ABC" Or [Balance]="XYZ",[Amount],0)

    and set the "Sum Over All" or "Sum Over Group" property for the text box. (Running sum??)

    ------------
    Things work differently in a report.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by ssanfu View Post
    In the footer, use
    =SUM(Text32)

    where Text32 is the name of the control that has the IIF() expression.
    Unless something has changed, you can't sum a calculated control:

    http://support.microsoft.com/kb/113354

    The running sum would work, but shouldn't be necessary. The posted formula should work, and I just successfully tested something similar.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664


    Now I remember ..... I had problems with something like this last year. I ended up putting the IIF() calc in the query, then using the query column name on the report and summing in the footer. (Unless I'm stuck on stoopid again)

    I hate it when I have to keep relearning things.


    Thanks Paul.

  6. #6
    RogerC is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    4
    Thank you, it worked! I created a new text box and reentered the formula and it worked flawlessly. Appreciate your input.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo!
    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: 7
    Last Post: 01-02-2013, 11:23 PM
  2. DCount with Multiple Criteria
    By Newbie11 in forum Reports
    Replies: 4
    Last Post: 05-25-2012, 09:04 AM
  3. If Then Else Multiple Criteria
    By GrayWolf in forum Programming
    Replies: 5
    Last Post: 04-12-2012, 07:27 PM
  4. Dlookups with multiple criteria
    By jtolsma in forum Programming
    Replies: 1
    Last Post: 04-03-2012, 04:33 PM
  5. Replies: 1
    Last Post: 07-13-2011, 11:00 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