Why Are Counts Different?

johnywhy

New Member
Joined
Sep 12, 2008
Messages
47
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
  2. MacOS
i'm confused. i'm doing a simple join with totals. i'm grouping on some fields, counting other fields. i would expect that all the COUNT fields would return identical counts, because they're all counting the same table. but the counts are different. why?

The attached image shows the query in design view. In Units table, each UnitID+TJC combo appears only once. In AggComplianceData, each combo can appear multiple times.

access1.png


Here's the sql:

PARAMETERS FromDate DateTime, ToDate DateTime;
SELECT AggComplianceData.TJC, Units.UnitName, AggComplianceData.UnitID, AggComplianceData.AHRI, Count(AggComplianceData.Finding) AS CountOfFinding, Count(AggComplianceData.Action) AS CountOfAction, Count(AggComplianceData.TJC) AS CountOfTJC
FROM AggComplianceData INNER JOIN Units ON (Units.TJC = AggComplianceData.TJC) AND (AggComplianceData.UnitID = Units.UnitID)
WHERE (((AggComplianceData.Period) Between [FromDate] And [ToDate]))
GROUP BY AggComplianceData.TJC, Units.UnitName, AggComplianceData.UnitID, AggComplianceData.AHRI;


Here's an excerpt of the results:

TJCUnitNameUnitIDIntAHRICountOfFindingCountOfActionCountOfTJC
2720Acute Rehab3c-ar16323
2720Acute Rehab3c-ar18222
2720Acute Rehab3c-ar58101
2720Acute Rehab3c-ar66111
2720Acute Rehab3c-ar69222
2720Acute Rehab3c-ar71545
2720Acute Rehab3c-ar72111
2720Acute Rehab3c-ar101022
2720Acute Rehab3c-ar200222
2720Bridges INPATIENT4e-brges1111

<tbody>
</tbody>



Here's the raw AggComplianceData for TJC 2720, UnitID 3c-ar, intAHRI 16:


SurveyIDTJCUnitIDPeriodFindingAHRIRootCauseActionDateDueIntAHRI
2720.3c-ar.21327203c-ar2/1/2013Missing times on some of progress noted.16


16
2720.3c-ar.61327203c-ar6/1/2013Admission progress not not signed; corrected on spot.16P&P not followedCorrected at tiome of survey6/1/201316
2720.3c-ar.71327203c-ar7/1/2013Dr. Abadee: Physician orders (multiple) were illegible.16


16

<tbody>
</tbody>
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Cross-post: Why Are Counts Different?

Please note our rules on Cross-Posting. While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule #10 here: Forum Rules).

This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered. For a more complete explanation on cross-posting, see here: Forum Rules).
 
Upvote 0
Perhaps the counts differ because of nulls in some of the fields. These would not be included in a count.
 
Upvote 0
Perhaps the counts differ because of nulls in some of the fields. These would not be included in a count.

that's what i thought. but if that's true, then why are we seeing 2 for this item, when there's only 1 non-null?

here's the raw data. there's only one non-null action (for 2720, 3c-ar, AHRI 16)
SurveyIDTJCUnitIDPeriodFindingAHRIRootCauseActionDateDueIntAHRI
2720.3c-ar.21327203c-ar2/1/2013Missing times on some of progress noted.16


16
2720.3c-ar.61327203c-ar6/1/2013Admission progress not not signed; corrected on spot.16P&P not followedCorrected at tiome of survey6/1/201316
2720.3c-ar.71327203c-ar7/1/2013Dr. Abadee: Physician orders (multiple) were illegible.16


16

<tbody>
</tbody>

here's the query results. Shows 2 CountOfAction:
TJCUnitNameUnitIDIntAHRICountOfFindingCountOfActionCountOfTJC
2720Acute Rehab3c-ar16323

<tbody>
</tbody>

If there's only one Action in the raw data, why is it counting 2?

thx
 
Upvote 0
You should investigate the possibility that the field has a zero length string in it. I would try some tests:

SELECT * FROM TABLE WHERE (TJC = 2720) AND (Action Is Null)

Does it show the two records or only one of them?
 
Upvote 0
solved. this fixed it:

UPDATE AggComplianceData Set Action = Null WHERE TRIM(Action) = "";

thx!

is there a way to mark the thread 'solved'?
 
Upvote 0
Good deal. We don't have the practice of marking threads solved on this forum so it's fine as is.
ξ
 
Upvote 0

Forum statistics

Threads
1,215,362
Messages
6,124,502
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top