Re: Total of choice two

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,


In addition to Jeff, John and Chris suggestions, you can try to simply make
a long ... long arithmetic expression:


SELECT id, iif( f1=2, 1, 0) + iif( f2=2, 1, 0 ) + iif( f3=2, 1, 0 ) + ...
+ iif( f25=2, 1, 0)
FROM myTable


It would be shorter if you worked on a normalized table:


SELECT id, COUNT(*)
FROM myNormalizedTable
WHERE CorrectnessCode = 2
GROUP BY id


assuming your table is like (fields name):


id Component CorrectnessCode





Hoping it may help,
Vanderghast, Access MVP


"T Horner" <THorner@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0B9E0386-089F-4521-A731-7F9ED602C2C5@xxxxxxxxxxxxxxxx
> The table is populated with the results of a form. My data are the results
> of
> Observations. Each Entry is a single observation. Each field represents
> different components of that observation. A Zero means that that component
> was not observed. A 1 means that that component was correct. A 2 means
> that
> that component was incorrect. I have a series of reports that return
> percentages of incorrect components for each field. These reports use
> Relationships to determine if certain areas are worse than others and so
> forth.
> I need to sum across these fields just to create a report that gives an
> overall look. By seeing the number of incorrect components per entry, we
> can
> see if the overall performance has increased over time or relationally to
> over things. Because of the need for relationships, I am using Access
> rather
> than Excel. This is the only place where I need to sum across fields.
>
> "Michel Walsh" wrote:
>
>> Hi,
>>
>>
>> Your data does not sound to be normalized, but lucky you, you MAY be able
>> to
>> use a crosstab, directly, to reach the result you seek:
>>
>> TRANSFORM Nz(COUNT(*), 0)
>> SELECT "total"
>> FROM myTable, PossibleChoices
>> WHERE d IN(f1, f2, f3, f4, f5)
>> GROUP BY "total"
>> PIVOT d
>>
>>
>> There are 2 tables, the original table, with fields( id, f1, f2, f3, f4,
>> f5) -- yours go up to 25, change the IN() clause appropriately
>>
>> and table PossibleChoices, one field, d, with as many record as there is
>> possible choice (ie, if there is 100 possible choices, that makes 100
>> records).
>>
>> The query returns the number of occurrences of each choice, "by id"...
>> and
>> unless a choice is NEVER used, the choice will appear under a field with
>> its
>> "name". In:
>>
>>
>> Query61
>> Expr1002 1 2 3 4 5 6 7 9
>> total 3 2 1 1 2 1 2 2
>>
>>
>>
>>
>> you can observe that choice "8" is missing, because no initial record
>> ever
>> speaks of it, in my data.
>>
>>
>> I also ASSUMED there is not duplicated selected choices, per original
>> record. If there are, the choice is counted once only.
>>
>> Table32
>> ID f1 f2 f3 f4 f5
>> 1 1 2 4 9 9
>>
>>
>> here, 9 is mentioned twice, but will be counted only once.
>>
>>
>>
>> For more than that, you SHOULD go to a normalized table design.
>>
>>
>>
>> Hoping it may help,
>> Vanderghast, Access MVP
>>
>>
>> "T Horner" <THorner@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:92B5210C-CA15-447E-9C19-7BD3DC45AF1C@xxxxxxxxxxxxxxxx
>> >I have a table that records a value of 0, 1, or 2 for about 25 fields. I
>> >need
>> > to know the total number of 1's and the total number of 2's for each
>> > entry. I
>> > was looking at a calculated field in a query but I don't know how to
>> > set
>> > it
>> > up.
>>
>>
>>


.



Relevant Pages

  • Re: Total of choice two
    ... Each Entry is a single observation. ... I have a series of reports that return ... By seeing the number of incorrect components per entry, ... > The query returns the number of occurrences of each choice, ...
    (microsoft.public.access.queries)
  • Re: New Record Update
    ... If the form is a subform, what is the name of the subform control on the ... > I have saved it and close the form and view my reports, ... >>MS Access MVP ... >>> combobox that allow me to choose an account. ...
    (microsoft.public.access.forms)
  • Re: Increasing report Width greater than 22 inches
    ... >>> most Access reports are) would be difficult for users to grasp if it were ... Microsoft is aware of customer demand for additional capability in ... >>> Microsoft Access MVP ...
    (microsoft.public.access.reports)
  • Re: pigeon hole report
    ... Duane Hookom ... "Bob Myles" wrote in message ... There are also some reports in the calendar reports and corp ... >> MS Access MVP ...
    (microsoft.public.access.reports)
  • Outlook calling CompareEntryId a lot after calling GetHierarchyTable
    ... symbol beside a folder in the folder view pane. ... |- 2002 Reports ... Compare entry Id for folder "2002 Reports" against entry Id for folder ...
    (microsoft.public.win32.programmer.messaging)