473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Average function not calculating correctly

35 32bit
Hello,

I am trying to compute the average of Cost of New based on the criteria below. However, for example if there are 18 records and there are only 2 that meet the criteria it is dividing by 18 instead of 2. How can I get this to work correctly? Thanks in advance for the help.

Expand|Select|Wrap|Line Numbers
  1. =Avg(IIf([Final]="TST-TST OK RTN" Or [Final]="NFF-TST & NFF" Or [Final]="RTN-RETURN" Or [Final]="SCL-SCR LOCALLY" Or [Final]="SCR-SCR RETURN" Or [Final]="BER-BER RTN CST",Nz([Cost Of New],0),0))
Jun 29 '15 #1

✓ answered by Rabbit

That's a very convoluted way of getting to what you need. It's better to put the criteria in the where clause, then all you need is Avg(Nz([Cost of New], 0))

4 1125
Rabbit
12,516 Expert Mod 8TB
It's working correctly as you have written it. You haven't filtered to number of records to 2, you're just changing the values of the other 16 records to 0. They're still there, so they're still used to calculate the average.

Rather than changing the values of the other 16 records, you need to filter out the other 16 records.
Jun 29 '15 #2
rhonda6373
35 32bit
Thanks Rabbit. I got it before I saw your reply by combining some other functions I had. I will try it your way as well so that I can understand.

Here is what works:
Expand|Select|Wrap|Line Numbers
  1. =Sum(IIf([Final]="TST-TST OK RTN" Or [Final]="NFF-TST & NFF" Or [Final]="RTN-RETURN" Or [Final]="SCL-SCR LOCALLY" Or [Final]="SCR-SCR RETURN" Or [Final]="BER-BER RTN CST",Nz([Cost of New],0),0))/Sum([Final]="TST-TST OK RTN" Or [Final]="NFF-TST & NFF" Or [Final]="RTN-RETURN" Or [Final]="SCL-SCR LOCALLY" Or [Final]="SCR-SCR RETURN" Or [Final]="BER-BER RTN CST")*-1
Jun 29 '15 #3
Rabbit
12,516 Expert Mod 8TB
That's a very convoluted way of getting to what you need. It's better to put the criteria in the where clause, then all you need is Avg(Nz([Cost of New], 0))
Jun 29 '15 #4
rhonda6373
35 32bit
Thank you. I will try that.
Jun 29 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: michael way | last post by:
I read the follow query about calculating median posted by Daivd Porta on 10/8/03. CREATE TABLE SomeValues (keyx CHAR(1) PRIMARY KEY, valuex INTEGER NOT NULL) INSERT INTO SomeValues VALUES...
7
by: | last post by:
How to call a function with variable argument list from another function again with variable argument list? Example : double average ( int num, ... ); double AFunct1 ( int num, ... ); double...
1
by: CapeCoder | last post by:
I'd like to use the Excel.WorksheetFunction library to compute median and percentiles in a user-defined function. I'd like to use the data from the calling report as the function argument. ...
1
by: CapeCoder | last post by:
I'd like to use the Excel.WorksheetFunction library to compute median and percentiles in a user-defined function. Rather than creating a SQL dataset in the function, I'd like to use the data from...
5
by: Carlo B | last post by:
I need to store numbers in an array and by using a class I need to calculate the average of the numbers entered. I cannot get the text box to return the total of the numbers in the average function...
3
by: C++Geek | last post by:
I need to get this program to average the salaries. What am I doing wrong? //Program to read in employee data and calculate the average salaries of the emplyees.
1
by: desktop | last post by:
I have stumbled upon different ways to declare a function template specialization. Are the following examples synonymous or are there significant differences: template<typename T // Primary...
1
by: Sedigh | last post by:
Hi Everybody, I need to write a macro on my Excel sheet to calculate the average of cells for me. This is the code I have written but the average function is not working. Can you please let me...
6
by: kumarboston | last post by:
Hi All, I am trying to get an average value for my data, here is my data file DATA FILE EP1934.PDB 250 250 11.27 EP1934.PDB 251 251 12.7332 EP1934.PDB 252 252 6.38341 EP1934.PDB 253 253...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.