Results 1 to 8 of 8
  1. #1
    carissa7 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2018
    Posts
    10

    Expression builder - if statement condition and Sum formula in a control source

    Hi all,



    I have a form I build in access db with a control source where I want to write a formula in that control source based on a table called " Entity master"
    The table has the following columns: child entity, parent entity, country of child, country of parent, and amounts

    I want the if statement to say the following. If(EntityMaster.CountryofChild) = "US" AND if(entitymaster.CountryofParent = "US" then sum up only the negative amounts in the amounts columns.

    Here is what I have below:

    Code:
    IIF([EntityMaster]).[ParentofJurisdictions]="United States",IIF([EntityMaster].[ChildOfJurisdiction]="United States",SUM([EntityMaster].[Amounts]))))
    How do I specific to only sum negative amounts? also i'm getting a #name? error message on the form

    .

    Any help is appreciated, thank you.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    try

    SUM(IIF([EntityMaster]).[ParentofJurisdictions]="United States" AND [EntityMaster].[ChildOfJurisdiction]="United States" AND [EntityMaster].[Amounts]<0,[EntityMaster].[Amounts],0)

  3. #3
    carissa7 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2018
    Posts
    10
    hmmm it says the "expression you entered contains too many arguments" although syntax is better than mine haha, thoughts?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Missing a closing paren. Parens, brackets, quotes, apostrophes must be in pairs when used as special characters and not literal text in strings.

    Probably don't need the table prefix.

    SUM(IIF([ParentofJurisdictions]="United States" AND [ChildOfJurisdiction]="United States" AND [Amounts]<0, [Amounts], 0))

    Why the 's' at end of ParentofJurisdictions and not ChildOfJurisdiction? And maybe capitalize the 'O' in 'of'.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    carissa7 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2018
    Posts
    10
    Actually I tried this:
    Code:
    =Sum(Amounts * IIF(CountryofChild="US" And CountryofParent="US"  And Amounts<0,-1,0))
    and it does sum the negative numbers, however it returns it with a positive. so it does -100 + -400 and returns a 500, any ideas?

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'd say that if Amounts is a negative number, then you're multiplying 2 negatives, which we know will create a positive. Your prior examples had no multiplication.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Well, the negative numbers are multiplied by -1. A neg times a neg is a pos.

    Why different sets of field names and values? In post 1, narrative shows one version and expression code shows another. Why confuse us?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    carissa7 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2018
    Posts
    10
    oh right ahhh ,okay thank you so much!!

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

Similar Threads

  1. Replies: 6
    Last Post: 03-07-2018, 06:05 AM
  2. Replies: 6
    Last Post: 09-26-2016, 10:36 PM
  3. Replies: 6
    Last Post: 05-17-2015, 01:22 PM
  4. Replies: 3
    Last Post: 04-30-2013, 05:32 AM
  5. Replies: 2
    Last Post: 07-30-2009, 08:02 AM

Tags for this Thread

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