dbTalk Databases Forums  

SUM(IIF counting in a query

comp.databases.ms-access comp.databases.ms-access


Discuss SUM(IIF counting in a query in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
schwallyhoo
 
Posts: n/a

Default SUM(IIF counting in a query - 07-22-2011 , 12:05 PM






I have a query which interrogates activities in an append query and counts stats up by week,
replacing if the week is in use, and adding if it is the first occasion.


I have various columns in the append query for counting the various category an activity can be in,
one that works perfectly well is:



In Testing:

This works fine.

I have another field in the query which records the percentage of completion of the activity. If it
is 100% complete i.e. the PerCentComp field in the underlying query is 100, I would like to count
that as well

I have tried various combinations like:

Sum(IIf([TFStatus]="In Testing" AND [PerCentComp] =100,1,0))


Sum(IIf([TFStatus]="In Testing" AND W[PerCentComp] =100W,1,0))


Sum(IIf([TFStatus]="In Testing" AND "[PerCentComp] ='"100"'",1,0))

But nothing appears to work.

Is this in fact imposible to do or have I just got the syntax wrong?

Thanks
J


--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #2  
Old   
christianlott1@yahoo.com
 
Posts: n/a

Default Re: SUM(IIF counting in a query - 07-22-2011 , 12:22 PM






If [PerCentComp] is a text field maybe:

Sum(IIf([TFStatus]="In Testing" AND [PerCentComp] ="100",1,0))

If [PerCentComp] is sometimes Empty/Null, this would cause problems.
Maybe then you'd use the Nz function or IsNull test.


Example where boolInput could be True, False, or Null:

Public Function ReturnStatusIsCurrent(boolInput As Variant) As Variant

If Not IsNull(boolInput) Then
If boolInput Then
ReturnStatusIsCurrent = "Current"
Else
ReturnStatusIsCurrent = "Historical"
End If
Else

End If

End Function

Reply With Quote
  #3  
Old   
Patrick Finucane
 
Posts: n/a

Default Re: SUM(IIF counting in a query - 07-22-2011 , 01:15 PM



On Jul 22, 12:22*pm, "christianlo... (AT) yahoo (DOT) com"
<christianlo... (AT) yahoo (DOT) com> wrote:
Quote:
If [PerCentComp] is a text field maybe:

Sum(IIf([TFStatus]="In Testing" AND [PerCentComp] ="100",1,0))

If [PerCentComp] is sometimes Empty/Null, this would cause problems.
Maybe then you'd use the Nz function or IsNull test.

Example where boolInput could be True, False, or Null:

Public Function ReturnStatusIsCurrent(boolInput As Variant) As Variant

If Not IsNull(boolInput) Then
If boolInput Then
ReturnStatusIsCurrent = "Current"
Else
ReturnStatusIsCurrent = "Historical"
End If
Else

End If

End Function
There's another possibility. I created a table. I stuck in "In
Testing", "In Testing[spc][spc][spc]", and "[spc]In Testing" and set
all 3 to 100, as well as some with and without null/blank values.
Those with spaces got trimmed when saved. So in these 3 recs I got
returned back 2. The one with the leading space was ignored. It
didn't matter whether or not the value was null or 100.

His first Sum() looks OK. I'd probably modify it to remove the
totals, create a column like IIf([PercentComplete]=100,1,0)) As
OneOrZero and see if I get a value in the column. When I do, change
it back to a GroupBy and add the SUM() around it.

Reply With Quote
  #4  
Old   
Bob Quintal
 
Posts: n/a

Default Re: SUM(IIF counting in a query - 07-22-2011 , 04:48 PM



schwallyhoo <sumone (AT) hotmail (DOT) com> wrote in
news:d6Sdnf3Zi6FFMLTTnZ2dnUVZ8oCdnZ2d (AT) giganews (DOT) com:

Quote:


I have a query which interrogates activities in an append query
and counts stats up by week, replacing if the week is in use, and
adding if it is the first occasion.


I have various columns in the append query for counting the
various category an activity can be in, one that works perfectly
well is:



In Testing:

This works fine.

I have another field in the query which records the percentage of
completion of the activity. If it is 100% complete i.e. the
PerCentComp field in the underlying query is 100, I would like to
count that as well

I have tried various combinations like:

Sum(IIf([TFStatus]="In Testing" AND [PerCentComp] =100,1,0))


Sum(IIf([TFStatus]="In Testing" AND W[PerCentComp] =100W,1,0))


Sum(IIf([TFStatus]="In Testing" AND "[PerCentComp] ='"100"'",1,0))

But nothing appears to work.

Is this in fact imposible to do or have I just got the syntax
wrong?

Thanks
J


Access often stores percentage values as 0.00 to 1.00
and displays them as 0% to 100% That may be part of your problem.

--
Bob Q.
PA is y I've altered my address.

Reply With Quote
  #5  
Old   
Bob Barrows
 
Posts: n/a

Default Re: SUM(IIF counting in a query - 07-22-2011 , 05:42 PM



schwallyhoo wrote:
Quote:
I have a query which interrogates activities in an append query and
counts stats up by week, replacing if the week is in use, and adding
if it is the first occasion.


I have various columns in the append query for counting the various
category an activity can be in, one that works perfectly well is:



In Testing:

This works fine.

I have another field in the query which records the percentage of
completion of the activity. If it is 100% complete i.e. the
PerCentComp field in the underlying query is 100, I would like to
count that as well

I have tried various combinations like:

Sum(IIf([TFStatus]="In Testing" AND [PerCentComp] =100,1,0))


Sum(IIf([TFStatus]="In Testing" AND W[PerCentComp] =100W,1,0))


Sum(IIf([TFStatus]="In Testing" AND "[PerCentComp] ='"100"'",1,0))

But nothing appears to work.

Is this in fact imposible to do or have I just got the syntax wrong?

Thanks
J
The biggest problem is you have not defined what "doesn't work" means. Do
you get error messages? If so, what are they? Do you get incorrect results?
If so, show us some sample data, followed by expected results, followed by
the results you obtained.

Reply With Quote
  #6  
Old   
schwallyhoo
 
Posts: n/a

Default Re: SUM(IIF counting in a query - 07-23-2011 , 04:50 AM



The errors are around syntax, apart from when I us the first option, which just returns 0.

The PerCentComp column in the query contains from 0 - 100 as an integer, another way of doing the
math would be to use another column when I use the append query using IIF then I would just use the
SUM(IIF as in all the other fields (there are more categories that the query sums)

J


--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #7  
Old   
Bob Barrows
 
Posts: n/a

Default Re: SUM(IIF counting in a query - 07-23-2011 , 07:10 AM



schwallyhoo wrote:
Quote:
The errors are around syntax, apart from when I us the first option,
which just returns 0.

The PerCentComp column in the query contains from 0 - 100 as an
integer, another way of doing the math would be to use another column
when I use the append query using IIF then I would just use the
SUM(IIF as in all the other fields (there are more categories that
the query sums)

Sorry, I don't understand what you're talking about. Show us some sample
rows in tabular form, followed by desired results in tabular form, followed
by the incorrect result from your query if you can get it to run without
error, that is. We need the exact wording of any errors you get, not just a
vague description.

Reply With Quote
  #8  
Old   
Kaj Julius
 
Posts: n/a

Default Re: SUM(IIF counting in a query - 07-24-2011 , 09:20 AM



"schwallyhoo" <sumone (AT) hotmail (DOT) com> skrev i en meddelelse
news:d6Sdnf3Zi6FFMLTTnZ2dnUVZ8oCdnZ2d (AT) giganews (DOT) com...
Quote:


I have a query which interrogates activities in an append query and counts
stats up by week,
replacing if the week is in use, and adding if it is the first occasion.


I have various columns in the append query for counting the various
category an activity can be in,
one that works perfectly well is:



In Testing:

This works fine.

I have another field in the query which records the percentage of
completion of the activity. If it
is 100% complete i.e. the PerCentComp field in the underlying query is
100, I would like to count
that as well

I have tried various combinations like:

Sum(IIf([TFStatus]="In Testing" AND [PerCentComp] =100,1,0))


Sum(IIf([TFStatus]="In Testing" AND W[PerCentComp] =100W,1,0))


Sum(IIf([TFStatus]="In Testing" AND "[PerCentComp] ='"100"'",1,0))

But nothing appears to work.

Is this in fact imposible to do or have I just got the syntax wrong?

Thanks
J
Not sure if I understand you correctly, but if you want to count the rows
that are either "In Testing" or 100% finished then you need to change your
IIf condition from AND to OR:

Sum(IIf([TFStatus]="In Testing" OR [PerCentComp] =100,1,0))

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.