Results 1 to 10 of 10
  1. #1
    beegee is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2016
    Posts
    12

    Trying to clean out the noise in a query

    Hi all,
    I wrote a query that gives me information like this:


    Claim line 1: pt name: scarecrow | doc: wizard | surgery: heart transplant | paid: 1 (1 = paid) | paid amt: $20


    Claim line 2: pt name: scarecrow | doc: wizard | surgery: heart transplant | paid: -1 (-1 = returned payment) | paid amt: -$20

    Claim line 3: pt name: scarecrow | doc: wizard | surgery: heart design and implant | paid: 1 | paid amt: $50



    When I run just a simple count of my paid surgeries, based on the above example, I will only get 1 surgery because the wizard got paid for only 1 and the transplant was cancelled out. The question is, how do I write the query to just show the claim that was not cancelled out (claim line 3)?

    Thank you in advance for your help on this question (which hopefully makes sense).

  2. #2
    Preston is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Posts
    55
    Quote Originally Posted by beegee View Post
    Hi all,
    I wrote a query that gives me information like this:


    Claim line 1: pt name: scarecrow | doc: wizard | surgery: heart transplant | paid: 1 (1 = paid) | paid amt: $20
    Claim line 2: pt name: scarecrow | doc: wizard | surgery: heart transplant | paid: -1 (-1 = returned payment) | paid amt: -$20

    Claim line 3: pt name: scarecrow | doc: wizard | surgery: heart design and implant | paid: 1 | paid amt: $50



    When I run just a simple count of my paid surgeries, based on the above example, I will only get 1 surgery because the wizard got paid for only 1 and the transplant was cancelled out. The question is, how do I write the query to just show the claim that was not cancelled out (claim line 3)?

    Thank you in advance for your help on this question (which hopefully makes sense).
    The best way to do it is with a Count aggregation. Select s.[surgery], count(s.[pt name]) as operationcount from (select distinct [pt name],[doc],[surgery] from tablename) as s

    But really, there should be a table for surgeries, and these payments should be in a separate table that has a many to one relationship to the surgery table.

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    could you try a grouped query using sum (Paid) first then run a select query to search for non-zero Paid field?

    scarecrows op by the wizard wouldn't show as the grouped query would cancel out as sum (1 and -1) = 0

  4. #4
    beegee is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2016
    Posts
    12
    Hi Andy, Thank you for your response.

    Hmmm... I tried that. I got both the $20 transplant and $50 heart design and implant, since they were both technically paid. Somehow I want Access to recognize only the payments for the pts that were paid and not returned. Even though they are in different rows.

  5. #5
    beegee is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2016
    Posts
    12
    Is that in sql? Can I do that in Access? There is a table for the surgeries and for what the docs get paid. I also made this into a separate table. I am so tempted to go through this manually and delete all of the kicked out payments since I can't figure out how to write this in Access.

  6. #6
    beegee is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2016
    Posts
    12
    Quote Originally Posted by Preston View Post
    The best way to do it is with a Count aggregation. Select s.[surgery], count(s.[pt name]) as operationcount from (select distinct [pt name],[doc],[surgery] from tablename) as s

    But really, there should be a table for surgeries, and these payments should be in a separate table that has a many to one relationship to the surgery table.
    Is that in sql? Can I do that in Access? There is a table for the surgeries and for what the docs get paid. I also made this into a separate table. I am so tempted to go through this manually and delete all of the kicked out payments since I can't figure out how to write this in Access.

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    SELECT tbltest.name, tbltest.doctor, tbltest.surgery, Sum(tbltest.paid) AS SumOfpaid, Abs([paidAmt]) AS Paid
    FROM tbltest
    GROUP BY tbltest.name, tbltest.doctor, tbltest.surgery, Abs([paidAmt])
    HAVING (((Sum(tbltest.paid))<>0));
    My second shot

    tbltest was just my table with your data

  8. #8
    beegee is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2016
    Posts
    12
    Quote Originally Posted by andy49 View Post
    My second shot

    tbltest was just my table with your data
    Good morning/afternoon Andy,
    That's really funny that you named it "tbltest" since I called it that as well... (could I really be on my way to being an Access expert???).

    I will definitely try the Abs function and let you know how it goes. I think that is exactly what I am looking for, though. So thank you very much!

    (btw, this is only my second time posting a question here, so should I mark it "solved" before or after I try it?)

  9. #9
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    No only mark as solved when the matter is done. My solution might not work for some reason and others can then look closely at it too

  10. #10
    beegee is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2016
    Posts
    12
    It worked!!! I checked was able to check against the claims and see that in fact this is exactly what happened and what got paid and finalized!!! Woo-hoo!!! Abs is my new best friend Thank you, Andy! Now where's that Solved button...

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

Similar Threads

  1. Macro Code Clean up
    By lonesoac0 in forum Macros
    Replies: 0
    Last Post: 08-01-2016, 07:37 AM
  2. Clean up report with a filter
    By Michael.Reynolds1775 in forum Forms
    Replies: 2
    Last Post: 04-02-2015, 07:03 AM
  3. Data Clean Up.
    By leungyen in forum Queries
    Replies: 14
    Last Post: 01-12-2015, 01:49 PM
  4. VBA Code Clean up?
    By need_help12 in forum Access
    Replies: 1
    Last Post: 04-20-2012, 03:00 PM
  5. Data clean
    By derf in forum Programming
    Replies: 0
    Last Post: 09-20-2008, 09:37 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