Results 1 to 7 of 7
  1. #1
    DerekW is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2021
    Posts
    5

    Building a query to display a count of leading digits in a dataset


    Hello,

    I am in need of assistance with building an Access query that will display a count of the number of times that a specific number is the leading digit in the Amount column in the attached dataset. For example, I am looking for a query that will tell me the number of times that "1" is the leading digit of the amount, that "2" is the leading digit of the amount, that "3" is the leading digit of the amount, and so on all the way to 9.

    I have attached a sample workbook to use with the data in it. Please let me know if you have any questions.

    Thanks,
    Derek
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This type of thing?

    SELECT Count(*) AS CountOfAmount
    FROM Transactions
    WHERE Left([Amount],1)="1"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Or this type of thing:

    SELECT Left([Amount],1), Count(*) AS CountOfAmount
    FROM Transactions
    GROUP BY Left([Amount],1)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    DerekW is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2021
    Posts
    5
    That second option works well for me, thank you. Now if I wanted to divide the count of each category by the total number of records, how would I do that? Put another way, how do I show the percentage amount of 1 as the leading digit out of all the records?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would do that in the form/report the query is being used for. You can do it in the query with a subquery to get the total, but it could be a performance nightmare.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    DerekW is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2021
    Posts
    5
    Okay, I have figured out how to give me that answer on percentages. Thanks for your help, solved my problem!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 12
    Last Post: 04-15-2019, 07:28 PM
  2. How can I count missing dates in a dataset
    By Banniskirk in forum Programming
    Replies: 3
    Last Post: 12-17-2018, 10:52 AM
  3. Replies: 7
    Last Post: 09-20-2014, 06:48 PM
  4. Replies: 4
    Last Post: 08-20-2014, 04:35 PM
  5. Replies: 9
    Last Post: 12-05-2013, 11:48 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