PC Review


Reply
Thread Tools Rate Thread

Creating a column-average in subform datasheet

 
 
mothie@gmail.com
Guest
Posts: n/a
 
      2nd Nov 2006
Hi,

I have been searching these forums for a while trying to find a
specific answer to a problem I am having. I have seen several responses
that skirt around the issue of creating form and querie averages, but
none that cover the angle I'm trying to find. I hope that it is fairly
straight-forward, as long as I write coherently! So please bear with
me.

I have a database that deals with a list of projects, each project
consisting of many tasks. I therefore have two tables, one for
projects, one for tasks, forming a one-to-many relationship. I have a
form where I can view a project; in this also a subform (in datasheet
view) where I can see the tasks that are associated with that project
(linked by a project ID).

One of the fields for the tasks is to keep track of how complete the
task is, expressed as a percentage. So when a task is in progress, I
can log on to the database, update the task [Compl_Status] field, and
so when I view the 'Project Details' form I can preview the progress of
each task in that Project.

The crux of my problem is that I want to be able to view the progress
of the *overall project*, i.e.

For ProjectTask 1 to n
Sum [Compl_Status] fields
Divide by number of Tasks associated to the Project
Display Average [Compl_Status] <==> Overall status of project

I had considered creating a field in the Projects table, to look up all
the different [Compl_Status]'s associated to that Project, and view the
average. But I understand that this would be a very bad practice, and
would result in 'bad data' - as every time I added a new task the
Project Status field wouldn't be updated. So I've resorted to try and
involve the total in either the subform, or by creating a query that
works out the average.

However, this has been to no avail. I can create a column in the
form/query which calculates an average of the column of field
[Compl_Status], but only for an individual task, not ALL the tasks.
What I envisage I need is to have the Task names forming the rows, with
columns for Task Duration, Days Completed, and of course the percentage
[Compl_Status], but with an extra 'row' at the bottom formulating the
average of the [Compl_Status] column. But I simply can't get my head
around what I'm doing wrong or how I need to edit the form I have to
accomodate what I'm trying to do.

I hope that my problem makes sense. Thanks so much for taking the time
to 'listen'! I hope that you'll be able to assist me in making sense of
what I'm trying to do!

Chris

 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3ByaW5rcw==?=
Guest
Posts: n/a
 
      2nd Nov 2006
Mothie,

In the form footer of your subform, place a textbox with the following
properties:

ControlSource: =Avg([YourField])
Visible: No

This will calculate the number you're looking for. To display it on the
main form, place a textbox that references it:

ControlSource: =[YourSubform].Form![YourSummaryField]

Sprinks

"(E-Mail Removed)" wrote:

> Hi,
>
> I have been searching these forums for a while trying to find a
> specific answer to a problem I am having. I have seen several responses
> that skirt around the issue of creating form and querie averages, but
> none that cover the angle I'm trying to find. I hope that it is fairly
> straight-forward, as long as I write coherently! So please bear with
> me.
>
> I have a database that deals with a list of projects, each project
> consisting of many tasks. I therefore have two tables, one for
> projects, one for tasks, forming a one-to-many relationship. I have a
> form where I can view a project; in this also a subform (in datasheet
> view) where I can see the tasks that are associated with that project
> (linked by a project ID).
>
> One of the fields for the tasks is to keep track of how complete the
> task is, expressed as a percentage. So when a task is in progress, I
> can log on to the database, update the task [Compl_Status] field, and
> so when I view the 'Project Details' form I can preview the progress of
> each task in that Project.
>
> The crux of my problem is that I want to be able to view the progress
> of the *overall project*, i.e.
>
> For ProjectTask 1 to n
> Sum [Compl_Status] fields
> Divide by number of Tasks associated to the Project
> Display Average [Compl_Status] <==> Overall status of project
>
> I had considered creating a field in the Projects table, to look up all
> the different [Compl_Status]'s associated to that Project, and view the
> average. But I understand that this would be a very bad practice, and
> would result in 'bad data' - as every time I added a new task the
> Project Status field wouldn't be updated. So I've resorted to try and
> involve the total in either the subform, or by creating a query that
> works out the average.
>
> However, this has been to no avail. I can create a column in the
> form/query which calculates an average of the column of field
> [Compl_Status], but only for an individual task, not ALL the tasks.
> What I envisage I need is to have the Task names forming the rows, with
> columns for Task Duration, Days Completed, and of course the percentage
> [Compl_Status], but with an extra 'row' at the bottom formulating the
> average of the [Compl_Status] column. But I simply can't get my head
> around what I'm doing wrong or how I need to edit the form I have to
> accomodate what I'm trying to do.
>
> I hope that my problem makes sense. Thanks so much for taking the time
> to 'listen'! I hope that you'll be able to assist me in making sense of
> what I'm trying to do!
>
> Chris
>
>

 
Reply With Quote
 
mothie@gmail.com
Guest
Posts: n/a
 
      2nd Nov 2006
Sprinks,

Thank you very much, that worked, albeit with a bit of tweaking!

For some reason, after doing what you suggested it returned a value of
0. I think it was because I had a calculated Control Source for the
field - i.e. the field that was being 'averaged' was dependent on two
other fields. These other fields were not null, so resulted in a value
being returned for the [Compl_Status] field - and yet the average
didn't return properly. Can you suggest why this was so?

Many thanks

Chris


Sprinks wrote:

> Mothie,
>
> In the form footer of your subform, place a textbox with the following
> properties:
>
> ControlSource: =Avg([YourField])
> Visible: No
>
> This will calculate the number you're looking for. To display it on the
> main form, place a textbox that references it:
>
> ControlSource: =[YourSubform].Form![YourSummaryField]
>
> Sprinks


 
Reply With Quote
 
=?Utf-8?B?U3ByaW5rcw==?=
Guest
Posts: n/a
 
      2nd Nov 2006
Mothie,

I'm not sure what your situation is, however, when you want to average a
calculated field, you need to average the calculation rather than the
calculated field itself. For example, if you wanted the average area of
rectangles, you need to use

Avg([Length] * [Width])

And I shouldn't have assumed that none of these might be Null, so you should
check each first, and convert any nulls to zeros:

Avg(Nz([Length]) * Nz([Width]))

This will still, however, give you the average over the total number of
records, regardless if a value is zero.

If you wish to total the average of all *non-zero* values, you could add an
invisible textbox to the Detail section with the Control Source set to:

=IIf(Nz([YourField])=0,0,1)

Let's call it, e.g., "NonZeros". You could return the non-zero average by
the following controls in the footer:

Total: =Sum([YourField])
Count: =Sum([NonZeros])
YourAverage: = [Total]/[Count]

Also, since everyone here always designs well-normalized databases , I'm
sure you really meant that your *form control* rather than your *field* was
dependent on two other fields.

Hope that helps.
Sprinks


"(E-Mail Removed)" wrote:

> Sprinks,
>
> Thank you very much, that worked, albeit with a bit of tweaking!
>
> For some reason, after doing what you suggested it returned a value of
> 0. I think it was because I had a calculated Control Source for the
> field - i.e. the field that was being 'averaged' was dependent on two
> other fields. These other fields were not null, so resulted in a value
> being returned for the [Compl_Status] field - and yet the average
> didn't return properly. Can you suggest why this was so?
>
> Many thanks
>
> Chris
>
>
> Sprinks wrote:
>
> > Mothie,
> >
> > In the form footer of your subform, place a textbox with the following
> > properties:
> >
> > ControlSource: =Avg([YourField])
> > Visible: No
> >
> > This will calculate the number you're looking for. To display it on the
> > main form, place a textbox that references it:
> >
> > ControlSource: =[YourSubform].Form![YourSummaryField]
> >
> > Sprinks

>
>

 
Reply With Quote
 
mothie@gmail.com
Guest
Posts: n/a
 
      3rd Nov 2006
Excellent, thanks a lot - that was just what I was missing. I didn't
realise you couldn't average a field if it's *control* was dependent
on the results of other fields...

Thanks for clearing up about use of the Nz() property as well - I had
wondered why people were using it! I'll keep that in mind, although in
my case the field is dependent on required fields so should always
return a not-null value.

Chris

Sprinks wrote:

> Mothie,
>
> I'm not sure what your situation is, however, when you want to average a
> calculated field, you need to average the calculation rather than the
> calculated field itself. For example, if you wanted the average area of
> rectangles, you need to use
>
> Avg([Length] * [Width])
>
> And I shouldn't have assumed that none of these might be Null, so you should
> check each first, and convert any nulls to zeros:
>
> Avg(Nz([Length]) * Nz([Width]))
>
> This will still, however, give you the average over the total number of
> records, regardless if a value is zero.
>
> If you wish to total the average of all *non-zero* values, you could add an
> invisible textbox to the Detail section with the Control Source set to:
>
> =IIf(Nz([YourField])=0,0,1)
>
> Let's call it, e.g., "NonZeros". You could return the non-zero average by
> the following controls in the footer:
>
> Total: =Sum([YourField])
> Count: =Sum([NonZeros])
> YourAverage: = [Total]/[Count]
>
> Also, since everyone here always designs well-normalized databases , I'm
> sure you really meant that your *form control* rather than your *field* was
> dependent on two other fields.
>
> Hope that helps.
> Sprinks
>
>
> "(E-Mail Removed)" wrote:
>
> > Sprinks,
> >
> > Thank you very much, that worked, albeit with a bit of tweaking!
> >
> > For some reason, after doing what you suggested it returned a value of
> > 0. I think it was because I had a calculated Control Source for the
> > field - i.e. the field that was being 'averaged' was dependent on two
> > other fields. These other fields were not null, so resulted in a value
> > being returned for the [Compl_Status] field - and yet the average
> > didn't return properly. Can you suggest why this was so?
> >
> > Many thanks
> >
> > Chris
> >
> >
> > Sprinks wrote:
> >
> > > Mothie,
> > >
> > > In the form footer of your subform, place a textbox with the following
> > > properties:
> > >
> > > ControlSource: =Avg([YourField])
> > > Visible: No
> > >
> > > This will calculate the number you're looking for. To display it on the
> > > main form, place a textbox that references it:
> > >
> > > ControlSource: =[YourSubform].Form![YourSummaryField]
> > >
> > > Sprinks

> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I reference the Second Column on a Datasheet Subform? Klatuu Microsoft Access Form Coding 6 3rd Apr 2008 03:18 PM
Creating a column-average in subform datasheet mothie@gmail.com Microsoft Access Queries 4 3rd Nov 2006 09:24 AM
Creating a column-average in subform datasheet mothie@gmail.com Microsoft Access Forms 4 3rd Nov 2006 09:24 AM
SubForm Datasheet Column widths Star Microsoft Access Forms 2 19th Aug 2005 02:28 AM
Column Width in SubForm that's a Datasheet Alex Microsoft Access Forms 2 20th Jul 2005 08:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:58 AM.