Results 1 to 3 of 3
  1. #1
    Qweequeg is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2022
    Posts
    2

    How do I count 2 or more values as 1, when each is residing in a separate rows (see attached)


    Hello Experts
    Looking at the snippet, I need to count the number of identical RPUIDS which are utilizing different electric meter classes. The attached example would count as '1'

    The RPUID is a property identifier number, and I need to count the properties (RPUIDs) which are simultaneously utilizing different meter classes.

    I was wondering if there is a way to use Sum(IIF, but I don't know how to use it in this scenario with the criteria residing in different rows.
    Most certainly would be grateful for some guidance.
    Attached Thumbnails Attached Thumbnails criteria.png  

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Use a nested subquery that returns DISTINCT records for RPUID, utility, and meterclass then count:

    SELECT RPUID, utility, Count(meterclass) AS CntClass FROM (SELECT DISTINCT RPUID, utility, meterclass FROM table) AS T GROUP BY RPUID, utility;
    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.

  3. #3
    Qweequeg is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2022
    Posts
    2
    Excellent! Thank-you, June7! Very much appreciate your assistance. As a novice, I've never used a nested query before. I had to fiddle with the syntax to make it work, but I definitely owe you a beer. Code worked out like so:

    Code:
    SELECT [meter].[RPUID] AS RPUID, [meter].[utility] AS UTILITY, Count(meter.meterclass) AS CountOfmeterclass
    FROM (SELECT DISTINCT RPUID, utility, meterclass FROM meter)  AS T
    GROUP BY T.RPUID, T.utility
    HAVING (((T.utility)="electric") AND ((Count([meter].[meterclass]))>1));
    The table contains several thousand records, and the code returned the count on every property, including properties with a single meterclass, so I had to filter those out using >1, but this worked great!

    Again, many thanks to you!

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

Similar Threads

  1. Replies: 11
    Last Post: 01-08-2020, 03:26 PM
  2. Replies: 5
    Last Post: 02-26-2019, 03:28 PM
  3. Replies: 7
    Last Post: 05-25-2018, 05:56 PM
  4. Replies: 3
    Last Post: 04-03-2016, 03:00 PM
  5. Replies: 3
    Last Post: 02-16-2016, 03:10 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