How to write formula that searches for a populated previous date if the date specifed doesn't exist in a data set?

Dawson14

New Member
Joined
Mar 29, 2018
Messages
1
Hey all, long time lurker, first time poster.

I'm currently having trouble finding a way to write a formula that v-vlookups a specified date and returns a value but also return the closest previous date if the specified date doesn't exist in the data set. I have successfully written a formula that can do this, but there are situations where I would need to nest 10+ IF statements to essentially cover all possibilities. Let me explain:

I am trying to build a very basic order growth predictor for the current sales year based on the previous 5 years of sales data. I want to be able to specify a date range in the top left corner of the file, and then populate the table with data by team based on the date range and year. I have data pulled by sales team and cumulative orders by day in another tab. Essentially the question I am trying to answer is "Hey, how much did orders grow between these two dates for this year range?". The issue I'm having is that you would think our data records would have 365 individual records for each year per sales team(that's how many days in a year...duh!), but if there was no order changes for a certain day, the day doesn't exist.

So say if I wanted to look up what the orders were on March 27th, and June 1st for Team A in 2013-2014.

[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]Start Year[/TD]
[TD]2013[/TD]
[/TR]
[TR]
[TD]End Year[/TD]
[TD]2013[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD][/TD]
[TD]Month[/TD]
[TD]Day[/TD]
[/TR]
[TR]
[TD]Start[/TD]
[TD]03[/TD]
[TD]27[/TD]
[/TR]
[TR]
[TD]End[/TD]
[TD]06[/TD]
[TD]01[/TD]
[/TR]
</tbody>[/TABLE]


Here is the table that gets populated

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD]2013[/TD]
[TD][/TD]
[TD][/TD]
[TD]2014[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Region[/TD]
[TD]Team[/TD]
[TD]27-Mar[/TD]
[TD]1-Jun[/TD]
[TD]% Growth[/TD]
[TD]27-Mar[/TD]
[TD]1-Jun[/TD]
[TD]% Growth[/TD]
[/TR]
[TR]
[TD]Pacific[/TD]
[TD]A[/TD]
[TD]328,084[/TD]
[TD]328,294[/TD]
[TD].1%[/TD]
[TD]254,594[/TD]
[TD]260,259[/TD]
[TD]2.2%[/TD]
[/TR]
[TR]
[TD]Pacific[/TD]
[TD]B[/TD]
[TD]165,114[/TD]
[TD]163,813[/TD]
[TD]-.8%[/TD]
[TD]188,442[/TD]
[TD]N/A[/TD]
[TD]N/A[/TD]
[/TR]
[TR]
[TD]Pacific[/TD]
[TD]C[/TD]
[TD]325,289[/TD]
[TD]320,751[/TD]
[TD]-1.4%[/TD]
[TD]270,255[/TD]
[TD]260,208[/TD]
[TD]-3.7%[/TD]
[/TR]
</tbody>[/TABLE]










As you can see, the record for June 1st 2014 in Team B doesn't exist so it gives back an N/A. Below you can see the table set where June 1st is missing along with May 30th. What I want to do is have a formula that can recognize that the date specified doesn't exist and then look back in history for the next date

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Team[/TD]
[TD]Day[/TD]
[TD]Order Change[/TD]
[/TR]
[TR]
[TD]Team B[/TD]
[TD]5/30/2013[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Team B[/TD]
[TD]6/02/2013[/TD]
[TD]140[/TD]
[/TR]
[TR]
[TD]Team B[/TD]
[TD]6/03/2013[/TD]
[TD]-191[/TD]
[/TR]
</tbody>[/TABLE]








Here is my current formula:

=IFERROR(IF($G$14<$B$2,"",VLOOKUP(CONCATENATE($C17,$H$15),Pivot!$A:$H,8,FALSE)),IF($G$14<$B$2,"",VLOOKUP(CONCATENATE($C17,$H$15-1),Pivot!$A:$H,8,FALSE)))

As you can see my current formula has an IFERROR that is essentially stating "If you get an error because the date doesn't exist, go back one day and grab that one". Since I have a two day gap it doesn't work. Now like I said in the beginning of the post, I could nest "IF" formulas all day long until I basically cover the largest data gap I have and call it a day. But since I like to learn new things and do things right, I wanted to see if there is anyway to CORRECTLY write this to take care of it. Any thoughts?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
That is certainly possible (and kind of prefered, rather that nesting 20 IF statements). but can you kindly upload a spreadsheet with some real-life sample data (no personal info, obviously) so i can see how your data is arranged, and type in "simulated" values in the cells u want the formula to be in, and then maybe color those red, so i can change that into a working, live formula.

u can upload to google, or dropbox and reply with a link.

Glad to (try to) help.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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