How to pull values using dates?

TurkeyFeast

New Member
Joined
Aug 15, 2017
Messages
4
I have data values for given dates and I want to create a formula that will pull the value from column B based on the date in Column A. However, I would like to have the inconsistently formatted data in Column A be organized by month. Is this possible?

the formula I am using for "avg cars per month" is: =IF(MONTH(A4)&MONTH(A5)=MONTH(C4),AVERAGE(B4:B5),IF(MONTH(A4)=MONTH(C4),B4,"false"))



Date
Cars
Month
Avg Cars per month
1/4/11
50
1/1/2011
50
2/1/11
60
2/1/2011
60
3/1/11
60
3/1/2011
60
3/25/11
42
3/1/2011
42
<- error, should be 51
4/5/11
67
4/1/2011
4/25/11
69
5/18/11
63
5/1/2011
5/20/11
64
6/6/11
66
6/1/2011
7/10/11
76
7/1/2011
7/18/11
51






<tbody>
</tbody>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Welcome to the Board!
Why is the row above it (the first record for March) showing 60? Wouldn't you want that record to show 51 as well?
If not, then maybe this is what you are looking for:
Code:
=IF(AND(MONTH(A4)=MONTH(C4),MONTH(A5)=MONTH(C4)),AVERAGE(B4:B5),IF(MONTH(A4)=MONTH(C4),B4,"false"))

What about the possibility of having more than two records for any month? Is that possible?
 
Last edited:
Upvote 0
Welcome to Mr Excel forum

Not sure i understand what you trying to do. See if this does what you need

Formula in D2 copied down
=AVERAGEIFS(B$2:B2,A$2:A2,">="&DATE(YEAR(A2),MONTH(A2),1),A$2:A2,"<="&EOMONTH(A2,0))

Hope this helps

M.
 
Last edited:
Upvote 0
Welcome to Mr Excel forum

Not sure i understand what you trying to do. See if this does what you need

Formula in D2 copied down
=AVERAGEIFS(B$2:B2,A$2:A2,">="&DATE(YEAR(A2),MONTH(A2),1),A$2:A2,"<="&EOMONTH(A2,0))

Hope this helps

M.

This equation worked great except for one problem. The data in column A expands farther down than months in column D. Is there an easy way to manipulate the equation or reformat the dates in column D without having to go thru one by one and move the dates down?

Thank you in advance!
 
Upvote 0
This equation worked great except for one problem. The data in column A expands farther down than months in column D. Is there an easy way to manipulate the equation or reformat the dates in column D without having to go thru one by one and move the dates down?

Thank you in advance!

I'm not following you. The formula i have suggested is to be placed in column D and uses only data in columns A and B - column C (months) is not needed.

M.
 
Last edited:
Upvote 0
I'm not following you. The formula i have suggested is to be placed in column D and uses only data in columns A and B - column C (months) is not needed.

M.

Lets say that the data in column A runs all the way down to row 100 - because some months have conducted more than 1 survey. When I place your equation into column D, it will only perform the correct calculation for the number of months I have (lets say 60 months or 5 years). So column A goes down to row 100 but column D, with the equation, only goes down to row 60. See the issue here?

This would be much easier to explain, but I cannot post a snapshot..
 
Upvote 0
Still confused. Couldn't you copy/drag down the formula in column D up to row 100?

M.
 
Upvote 0
@TurkeyFeast

I've read your PM. Private support is not recommended in this forum.

Try to post a data sample here, in the thread, along with expected results, so others members also can help.
There are several ways to post a data sample. See section B in
Guidelines for Forum Use

M.
 
Last edited:
Upvote 0
Thank you for the update.

Haha, I was making a silly mistake and changed the values in your formula to stretch the entire length of the data. final working formula is:

=AVERAGEIFS(C5:C346,B5:B346,">="&DATE(YEAR(X6),MONTH(X6),1),B5:B346,"<="&EOMONTH(X7,0))

**column A is B in the formula. Column B became C. Column D became X. only big difference was changing the ranges.

Thanks for all of your help!
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,171
Members
449,296
Latest member
tinneytwin

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