Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    IIF Statement

    Dear All,




    I am trying to write an IIf statement to feature the formula below. The formula is in my report

    The some of amount = 0, and therefor the result of my formula below is returning a result #Num!

    =Sum([Sum total of records])/Sum([SumOfAmount])
    anks

    =IIf([SumOfAmount]=0,0,[Sum total of records]/[SumOfAmount])

    Can someone please tell me what is wrong with the above statement.

    Th

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    When [SumOfAmount] = 0 , the iif does not prevent the expression [Sum total of records]/[SumOfAmount] from being evaluated, which results in division by 0.

    Try something like this:

    IIf([SumOfAmount]=0,0,[Sum total of records]/iif([SumOfAmount]=0,1,[SumOfAmount])

    This will give you 0 if SumOfAmount=0, otherwise it gives you the result of [Sum total of records]/[SumOfAmount], which is what you are looking for.

  3. #3
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    IIf statement

    Hi John,
    Thanks for your reply.
    I tried your suggestion, and it fixed one, and created another. See attached report in pdf of the original report, and the new report using the formula you sent.
    Any other suggestion. I am also attaching a screen shot of the formulas.

    Thanks

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    are [Sum total of records] and [SumOfAmount] actually 0 or are they nulls? - look at your recordsource query - do you see 0's there? - make sure there is no formatting properties specified for the fields to show 0 when null

  5. #5
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Hi John,
    I got that one working, but I have another similar formula I need to make using

    where I need Sum([SumOfRecords1])/Avg([Amount]) using the IIf =0 It tells me I have too many arguments. Again this formula is in the report

    Thanks

  6. #6
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Hi Ajax,
    The values are 0. I got that one working, but using the formula John sent I cant fix the other one I just posted. RE
    where I need Sum([SumOfRecords1])/Avg([Amount]) using the IIf =0 It tells me I have too many arguments. This is a formula in my report.

    I need this for work in the morning, I appreciate any assistance.

    Thanks

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    what is the full formula? - too many arguments says what the problem is

    iif(something is true, then do this, otherwise do that) - 3 arguments

    you seem to have spaces in your field names, you are probably missing a square bracket

  8. #8
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    =IIf([SumOfAmount]=0,0,[Sum total of records]/IIf([SumOfAmount]=0,1,[SumOfAmount]))

  9. #9
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    IIf statement

    Please see attached Document. I hope this explains my problem.

    Thanks
    Attached Files Attached Files

  10. #10
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Sorry I thought I had the previous on e fixed, but I got confused. Indeed in the previous set of reports, the ones with the zero for all fields got fixed when I used the formula from John, but it made an error calculation for 1.1 heading and details 1.1.1 . I do hope I can get some assistance.

    Thanks very much.

  11. #11
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    your form images are unreadable - you need a higher resolution, perhaps zoom in on the affected controls.

    Also show the recordsource to your report and the rows where you are getting your error

    Also, do the relevant tables use lookup, calculated or multivalue fields?

    #num usually means nulls - so also try

    =IIf(nz([SumOfAmount],0)=0 or nz([Sum total of records])=0,0,nz([Sum total of records])/nz([SumOfAmount]))

  12. #12
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    IIIF Statement

    Can I please send a small version of the database?



    Thanks

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    yes - zip it and attach the zipped file

  14. #14
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    IIf statement

    Thank you. It is attached. The reports that I have the problem with is the

    Summary table of budget consumption by Budget Heading

    Detail table of Expenditure by Budget Heading

    Kind regards

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    sorry - horribly complex - I can't find either report you are referring to. Please remove all unnecessary queries, forms and reports so we can see what we are looking at - and remove the autoexec!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  2. Need help with a Like statement
    By itm in forum Queries
    Replies: 3
    Last Post: 10-22-2012, 12:55 PM
  3. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. If Statement Help
    By vennies83 in forum Queries
    Replies: 1
    Last Post: 06-09-2011, 03:50 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