Solved

Average If year in excel 2007

Posted on 2011-02-14
6
1,007 Views
Last Modified: 2013-12-13
Hi,

I'm trying to get the average if the year = 2009 or 2010 etc ...

I tried to use this this formula but it gives me 0 :

=AVERAGE(IF(YEAR(Table3[Date])=2009,Table3[Pricing]))

Open in new window


Please help.


Thank you so much for your time.
0
Comment
Question by:Dido123
6 Comments
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 34893302
Hello Dido123,

That formula should work but it's an "array formula" and as such you need to confirm with CTRL+SHIFT+ENTER so that curly braces like { and } apear around the formula in the formula bar.

...or use AVERAGEIFS function

=AVERAGEIFS(Table3[Pricing],Table3[Date],">="&DATE(2009,1,1),Table3[Date],"<"&DATE(2010,1,1))

regards, barry
0
 
LVL 3

Expert Comment

by:OblivionSY
ID: 34893308
I would move the IF statement to the outter clause.

=IF(YEAR(Table3[Date])=2009, AVERAGE(Table3[Pricing]), "Whatever to do if not 2009")

Have not tested that code - but if you supply an excel doc. would be able to have a look in detail.

I am not sure about your YEAR(Table3[Date]) part... would need to see the excel document to commment further
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34893323
I think that the problem with your approach is the cells that are not from 2009 are still included in the AVG calculation.

You may have better luck using a combination of SUMIF and COUNTIF functions instead of AVERAGE.

You'll need to replace date-column-range and pricing-column-range with the proper range expression.

=( SUMIF(date-column-range, 2009, pricing-column-range) / COUNTIF(date-column-range, 2009) )

Open in new window

0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 500 total points
ID: 34893334
Hello Oblivion SY,

That won't work I'm afraid - Dido's syntax is OK as I say - it just needs array entering.

sjklein42. The use of YEAR in the formula suggests that the Date field contains a date so you can't use just 2009 in a SUMIF criteria, that won't sum anything.....

See attached for examples of my two suggestions above and a third option which allows you to put the year in a cell I1 and use

=AVERAGEIFS(Table3[Pricing],Table3[Date],">="&DATE(I1,1,1),Table3[Date],"<"&DATE(I1+1,1,1))

regards, barry
26821278.xlsx
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 34893354
...on second thoughts....perhaps you are correct sjklein42, apologies. If there is just a year in the date column then that would be consistent with the formula producing a zero result. If that is the case then you can use sjklein's SUMIF/COUNTIF suggestion or AVERAGEIF like

=AVERAGEIF(Table3[Date],2009,Table3[Pricing])

regards, barry
0
 

Author Closing Comment

by:Dido123
ID: 34893424
barryhoudini, thank you so much!

Both your suggestions worked like a charm!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question