Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Queries with Null Value:

Status
Not open for further replies.

Tamrak

MIS
Jan 18, 2001
213
US
Hello Experts,

I would like to do calculation based on a query. Let me give you an example of the table structure. Let call it Project. Each officer will score the project like following example below. There are some null values in the record.


ProjectID Officers Item1 Item2 Item3 Item4 Item5 Item6 Item7
50 Mr. A 1 2 3 1 0 1 2
50 Mr. B 1 0 3 0 1 2
50 Mr. C 1 2 3 0 0 0 1
50 Mr. D 0 2 3 1 0 1 0
50 Ms. E 1 3 2 2
50 Ms. F 2 1 2 2 1 3 3
50 Ms. G 3 1 2 2
50 Ms. H 0 1 3 2 2 3
50 Ms. I 1 2 2 3 3 3 1
50 Mr. J
50 Mr. K 3 2 1 1 2 2
52 Mr. A 0 1 0 0 3 1 1

Each project will have 12 officers to record scoring from item1 to item7.

Conditions:

a.Score on each item will be null or less than 3
b.Each item has its own weight. For example, Item1 weights 2 points. Item2 = 4; Item3 =4; Item4 = 3; Item5 = 2; Item6 = 1; and Item7 = 1.

What we need to do:

1. Create a query that will sum Item1 to Item7, even with Null value. I will call ScoreTotal. For example, total score for Project # 50 of Mr. A, will be equal to [1*2]+[2*4]+[3*4]+[1*3]+Null+[1*1]+[2*1], which give us the result of: 29 ; Mr. B will be equal to 18 and so on..

2. After getting the ScoreTotal for all 12 Officers, I need to average them into one number for each project. We have to ensure that the null value will not be calculated. There will always be 12 officers for the project. We can name this field or function: AverageProjectScore. However, some officers might decide to skip in giving the score, such as officer J.

I do appreciate your help. I am stucking with these null value. I cannot use a simple average because some officers might skipping the score. I cannot just divide by 12.

Thanks again.
 
KenReay,

Based on your response, can you elaborate a little bit? Can you give me an example of how you are using NZ function in my example?

How can I use it to come up with average score?

Thanks.

 
Hi

I thought I did give an example?

you formula needs to be something like

(Nz([Item1],0)*1) + nz([Item2],0)*4) ...etc

Like I said read help

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
KenRaey,

NZ factor will not work due to the following reason:

1. If there is no entry for that officer, I receive the ScoreTotal of zero. The correct logic should be blank. I am tryting to avoid this one.

It will sum the score, if I have an entry in item1 to Item # 7.

2. Let's say that the ScoreTotal are working for some of the officers, how can I average them? What I am trying to do is to sum all of the ScoreTotal of available officers and divided them by the total number of the officers who input. The denominator can be ranged from null to 12.

Thanks again.
 
You may consider do the stat on a normalization query:
SELECT ProjectID, Officers, 1 As Item, Item1 As Score
FROM Projects WHERE Nz(Item1,0)<>0
UNION SELECT ProjectID, Officers, 2, Item2
FROM Projects WHERE Nz(Item2,0)<>0
...
UNION SELECT ProjectID, Officers, 7, Item7
FROM Projects WHERE Nz(Item7,0)<>0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you for all of your replies.

I think I have # 1 working right now. I used the ideas of KenRaey with the following:

ScoreTotal = (Nz([Item1],0)*2)+(nz([Item2],0)*4)+(nz([Item3],0)*4)+(nz([Item4],0)*3)+(nz([Item5],0)*2)+(nz([Item6],0)*1)+(nz([Item7],0))

Then, I created another field called -> ScoreTotal1. I put the following formula:

ScoreTotal1 --> =IIF (ScoreTotal = 0,Null,ScoreTotal)

Look like I got problem # 1 resolved.


Now, go to Problem # 2 -> How can I pull the total amount of the ScoreTotal1 and average them? Will try to figure out. Thanks again.
 
To solve your 2 problems in one go, I suggest you to create a saved query with the normalization union I suggested you in my previous post, and then do the total, count and average based on this query.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top