Results 1 to 6 of 6
  1. #1
    detlion1643 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    5

    SUM in regards to nulls

    I've been using the nz function lately, but it's starting to mess with other calculations by putting 0's in when I don't need a value in there. So i thought about using the iif function but can't really see what i'm doing wrong.

    It basically goes like this: if value1 is null, then return null. if value1 is not null, then check value2/3. if value2 is null and value3 is null, then return value1. if value 2 is null and value3 is not null, then return value1-value3. if value2 is not null and value3 is null, then return value1-value2. if value1/2/3 are all not null, then return value1-value2-value3.

    IIF(Canon_PG.[Ingram Price] is null,null,iif(Canon_$.[$] is null, iif([Canon_%].IM is null, null, SUM(Canon_PG.[Ingram Price]-[Canon_%].IM),iif([Canon_%].[IM] is null,SUM(Canon_PG.[Ingram Price]-[Canon_$].[$]),SUM(Canon_PG.[Ingram Price]-[Canon_$].[$]-[Canon_%].[%]))))) AS [IM TC]

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,923
    Look into using the IsNull() function.
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  3. #3
    detlion1643 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    5
    I tried the isnull(), but not sure if I used it right? Anyways, using this gets me the error about including the expression as part of an aggregate function. Tried putting it in the GROUP BY clause as well, but no avail, same error.

    IIF(isnull(Canon_PG.[Ingram Price]),null,IIF(isnull([Canon_$].[$]),IIF(isnull([Canon_%].[%]),Canon_PG.[Ingram Price],SUM(Canon_PG.[Ingram Price]-[Canon_%].[%])),IIF(isnull([Canon_%].[%]),SUM(Canon_PG.[Ingram Price]-[Canon_$].[$]),SUM(Canon_PG.[Ingram Price]-[Canon_$].[$]-[Canon_%].[%])))) AS [IM TC]

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,923
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  5. #5
    detlion1643 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    5
    Yes, unfortunately I am. All my tables come linked from excel (I'm migrating the excel to access, as the business had no structure behind this). I got it working anyways:

    IIf(IsNull(Canon_PG.[Ingram Price]),Null,IIf(IsNull([Canon_$].[$]),IIf(IsNull([Canon_%].IM),Canon_PG.[Ingram Price],Sum(Canon_PG.[Ingram Price]-[Canon_%].IM)),IIf(IsNull([Canon_%].IM),Sum(Canon_PG.[Ingram Price]-[Canon_$].[$]),Sum(Canon_PG.[Ingram Price]-[Canon_$].[$]-[Canon_%].IM)))) AS [IM TC]

    Just took some time trying to debug all of that.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,923
    At least you got it working. That's great. Thanks for posting back.
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

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

Similar Threads

  1. Replies: 2
    Last Post: 01-18-2010, 11:52 AM
  2. Sort Order Variation with nulls
    By jonsuns7 in forum Queries
    Replies: 1
    Last Post: 10-09-2009, 03:10 AM
  3. GetRows - Invalid Use of Nulls
    By Wannabe_Pro in forum Programming
    Replies: 3
    Last Post: 07-22-2009, 07:07 AM
  4. Replies: 1
    Last Post: 07-14-2008, 12:15 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