Results 1 to 3 of 3
  1. #1
    turnbuk is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    10

    Complicated Query Build...the story of my life

    I have a table that shows single transactions by line and includes the columns



    Card Holder Name
    Charge to Facility
    Amount Charged
    Merchant Name
    Transaction Date

    The problem I have is that there are negative amounts that show up in my data. This indicates that the original charge was transferred to a different facility. The card holder name will always stay associated with these transactions and only the facility number will change. For Example:

    Card Holder Name Charge to Facility Amount Charged Merchant Name Transaction Date
    Smith, Joe 987654321 $100.00 The Store 11/1/2012
    Smith, Joe 987654321 -$100.00 The Store 11/10/2012
    Smith, Joe 123456789 $100.00 The Store 11/10/2012

    So here we see the initial charge, then the transfer out, then the charge applied to the correct facility. The problem I have is that I cannot get accurate counts or amounts because of these negative numbers and transfers to different facilities. They’re not actual charges (only the first one is) and for the life of me I cannot figure how to write a query that would take this into consideration. In my head and can verbally say what I want to happen but I can’t figure out how to apply it in access.

    “Group by Card Holder Name, Count the number of ALL Transactions that are greater than ZERO, Count the number of negative Transactions and Subtract that count from the count of ALL Transactions great than ZERO”

    So my final product would be: There are TWO positive amounts in my example above which means my total count would be 2. But there is ONE negative amount listed so I need to subtract that from my original total count of TWO. Thus, my total count of actual transactions is ONE.

    I don’t have enough access knowledge to write an SQL statement so what I’m working on accomplishing I have only tried using the basic query tools in access.

    Man I hope this makes sense to somebody. I’ve been killing my brain on this one…..


    ~Kevin

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Code:
    SELECT
       TT.[Card Holder Name],
       SUM(TT.[Amount Charged]) AS NetAmountCharged,
       SUM(IIF(TT.[Amount Charged]>0,1,IIF(TT.[Amount Charged]=0,0,-1))) AS NetNumberofCharges
    FROM 
       MyTableName AS TT
    GROUP BY [Card Holder Name]

  3. #3
    turnbuk is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    10
    Thanks! That worked. Just what I needed.

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

Similar Threads

  1. A life jacket please
    By vampire12 in forum Access
    Replies: 6
    Last Post: 06-13-2013, 02:11 PM
  2. MOST COMPLICATED query ever
    By dastr in forum Queries
    Replies: 1
    Last Post: 07-05-2012, 04:29 AM
  3. Query with Complicated Requirements
    By Briana in forum Queries
    Replies: 1
    Last Post: 06-13-2012, 08:05 PM
  4. How to build query
    By kashif.special2005 in forum Queries
    Replies: 2
    Last Post: 03-02-2012, 02:18 AM
  5. ActiveX and Access: A Love Story
    By itsthegrimace in forum Access
    Replies: 1
    Last Post: 09-08-2011, 10:36 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