Average If in an array formula using Month Function

hitmanwa

Board Regular
Joined
Feb 13, 2008
Messages
70
Any particular reason this array formula won't work? If I remove the or it works fine but I'm trying to get the average for the current month and the previous month. B1=Current Date.



=AVERAGE(IF(MONTH('Q.A.History'!C1:IV1)=or(MONTH(B1),MONTH(B1)-1),'Q.A. History'!C21:IV21))
 
Last edited:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Any particular reason this array formula won't work? If I remove the or it works fine but I'm trying to get the average for the current month and the previous month. B1=Current Date.



=AVERAGE(IF(MONTH('Q.A.History'!C1:IV1)=or(MONTH(B1),MONTH(B1)-1),'Q.A. History'!C21:IV21))
If the date in B1 is in the month of January then MONTH(B1)-1 = 0. Is that your intention?
 
Upvote 0
No, but I can see that will be a problem too. I'm trying to get an average for a report that's using the current date as the criteria. If today is the 1st then there won't be any data so I wanted it to include the previous month's data. I've tried the formula using the and function and the or function.

Thanks for the quick reply.
 
Upvote 0
This machine is running 2000 :mad: I went ahead and added an iserror argument and it works. Is that the most efficient way to do this? I guess since there's no data for the current month it won't work.
 
Upvote 0
This machine is running 2000 :mad: I went ahead and added an iserror argument and it works. Is that the most efficient way to do this? I guess since there's no data for the current month it won't work.
Maybe something like this...

Array entered**:

=AVERAGE(IF(DAY(B1)>1,IF(MONTH(Q.A.History!C1:I1)=MONTH(B1),Q.A.History!C2:I2),IF(MONTH(Q.A.History!C1:I1)=MONTH(B1-DAY(B1)),Q.A.History!C2:I2)))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Assuming no empty cells within the range.
 
Last edited:
Upvote 0
Maybe this (confirm with ctrl+shift+enter)
=AVERAGE(IF(Q.A.History!C1:IV1>=DATE(YEAR(B1),MONTH(B1)-1,1),Q.A.History!C21:IV21))
 
Upvote 0

Forum statistics

Threads
1,224,608
Messages
6,179,872
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top