+ Reply to Thread
Results 1 to 7 of 7

DCount criteria

  1. #1
    Forum Contributor
    Join Date
    07-06-2006
    Posts
    108

    DCount criteria

    Hi,

    When using the DCount function it counts the criteria for all the records. I want it to be limited to count for a specific value in a field.

    My current build looks as followed:
    AutoCountBE25: DCount("[POrg]='BE25'";"[Automation Ratio - Purchasing organisations BE25 and BE05]";"[Auto/Man]='auto'")

    As you can see in the attached Datasheet View it still counts "auto" for all the records instead of those for BE25 in the POrg field. AutoCountBE25 and ManCountBE25 should total BE25Count.
    Attached Images Attached Images

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,318

    Re: DCount criteria

    Hi TomBP,

    Why not use a =CountIf instead?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: DCount criteria

    Quote Originally Posted by MarvinP View Post
    Hi TomBP,

    Why not use a =CountIf instead?
    This is a question regarding Access. There is no countif function in Access; only in Excel.

    Now to the question of the solution. Change your DCount to read
    AutoCountBE25: DCount("[POrg]";"[Automation Ratio - Purchasing organisations BE25 and BE05]";"[Auto/Man]='auto'")

    Now in the QBE, in the criteria for the field POrg, put =BE25. It will bring back only the records which have BE25 in the field POrg.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,318

    Re: DCount criteria

    Hey Alan,
    Sorry about my stupid reply. My mindset is always Excel based on how many questions we get on Access. I was wondering why he needed DCount and Advanced Formula type formatting. Now that you point out the question is about Access it makes a lot more sense. I'll read harder before making silly suggestions.

  5. #5
    Forum Contributor
    Join Date
    07-06-2006
    Posts
    108

    Re: DCount criteria

    Quote Originally Posted by alansidman View Post
    Now to the question of the solution. Change your DCount to read
    AutoCountBE25: DCount("[POrg]";"[Automation Ratio - Purchasing organisations BE25 and BE05]";"[Auto/Man]='auto'")

    Now in the QBE, in the criteria for the field POrg, put =BE25. It will bring back only the records which have BE25 in the field POrg.

    Alan
    Alan,

    I've tried your solution (Sample Database - Solution Alan) and it works. I'm however trying to combine more counts into one query (Datasheet View 2.jpg). This to reduce the number of query's.

    Is this even possible in Access?

    P.S. the Datasheet View 2 is a result of Query1 in the Sample Database.
    Attached Images Attached Images
    Attached Files Attached Files

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,717

    Re: DCount criteria

    Tom;
    Is this what you are looking for? Look at Query 4 in the db Attached. I created two separate queries, 2 and 3 that gave me the counts for each BE05 created by each and BE25 created for each. I then renamed the fields that contained the BE05 and BE25 information so that I could then create a union query based upon both Query 2 and Query 3. Note that Union Queries cannot be built in the QBE but only using SQL.

    Alan
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    07-06-2006
    Posts
    108

    Re: DCount criteria

    Alan,

    That's not what I'm looking for. Even if the numbers come out right, the quantity/difficulty of query's is too much hassle.

    Instead I'd rather make two seperate query's. One for BE25 and one for BE05.

    P.S. Sorry for the late response. Was out of the country.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1