Solved

Average If year in excel 2007

Posted on 2011-02-14
6
1,042 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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