Avoiding ifs within ifs

TheNewGuy22

New Member
Joined
Mar 19, 2014
Messages
38
Hello Everybody again,

I'm having difficulty figuring out how to set up an if statement without putting 12 ifs within each other.

I'm trying to get a formula that recognizes what month it is and then displays either FYyy or yyyy based on the month it shows and the date.

This is what I have. I want a way to get the bolded result based on the columns already there.

NovFY0911/5/200812/5/20082008
DecFY0912/6/20081/6/20092008
JanFY091/7/20092/4/20092009
FebFY092/5/20093/5/20092009
MarFY093/6/20094/3/20092009
AprFY094/4/20095/5/2009FY09
MayFY095/6/20096/3/2009FY09
JunFY096/4/20097/6/2009FY09
JulFY107/7/20098/5/2009FY10
AugFY108/6/20099/3/2009FY10
SepFY109/4/200910/5/2009FY10
OctFY1010/6/200911/3/20092009

<tbody>
</tbody>

Is there a way to list off say:
{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec} and then have an equivalent array with the possible outcomes?

Thank you very much,
Robin
 
@Rick Rothstein

Column AColumn BColumn CColumn DColumn E
DecFY0911/29/200812/29/20082008

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>

Those are the entries I'd want from your dates.


@BiocideJ

I've tried both equations several times and I'm getting the same results.

I've modified the equation slightly to not show anything if the date field is empty.

Code:
=IF((C11+((D11-C11)/2)=0),"",TEXT(C11+((D11-C11)/2),"MMM"))

Column AColumn BColumn CColumn DColumn E
JulFY097/16/20088/14/2008FY09
AugFY098/15/20089/15/2008FY09
SepFY099/16/200810/14/2008FY09
OctFY0910/15/200811/14/20082008
NovFY0911/15/200812/16/20082008
DecFY0912/17/20081/15/20092008
JanFY091/16/20092/13/20092009
MarFY092/14/20093/16/20092009
MarFY093/17/20094/15/20092009
AprFY094/16/20095/14/2009FY09
MayFY095/15/20096/12/2009FY09
JunFY096/13/20097/15/2009FY09

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>


I'd like the first Mar labeled to show up as Feb.
 
Upvote 0

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.
What is the reasoning that this should show as February? I'm not questioning whether it should or shouldn't as that is up to you. I just need to understand the convention that determines which month name to display so I can adjust the formula accordingly. Initially you had mentioned that it was the month that had more days in the date range, but perhaps there is more to it?
 
Upvote 0
Column A
Column B
Column C
Column D
Column E
Jul
FY09
7/16/2008
8/14/2008
FY09
Aug
FY09
8/15/2008
9/15/2008
FY09
Sep
FY09
9/16/2008
10/14/2008
FY09
Oct
FY09
10/15/2008
11/14/2008
2008
Nov
FY09
11/15/2008
12/16/2008
2008
Dec
FY09
12/17/2008
1/15/2009
2008
Jan
FY09
1/16/2009
2/13/2009
2009
Mar
FY09
2/14/2009
3/16/2009
2009
Mar
FY09
3/17/2009
4/15/2009
2009
Apr
FY09
4/16/2009
5/14/2009
FY09
May
FY09
5/15/2009
6/12/2009
FY09
Jun
FY09
6/13/2009
7/15/2009
FY09

<TBODY>
</TBODY>


I'd like the first Mar labeled to show up as Feb.

Unless I am wrong, Column A appears to be simply month in 3 characters text format of Column C

So why not simply the below formula for 2/14/2009 to show as Feb:

Code:
=TEXT(C2,"mmm")
 
Upvote 0
Unless I am wrong, Column A appears to be simply month in 3 characters text format of Column C

So why not simply the below formula for 2/14/2009 to show as Feb:

Code:
=TEXT(C2,"mmm")

If only, but see his first example in the above post
Column AColumn BColumn CColumn DColumn E
DecFY0911/29/200812/29/20082008

<TBODY>
</TBODY>
 
Upvote 0
I have many data points that have a wide range of dates that could start at any day of the month. These start and end dates could last anywhere from 25-35 days. There are 12 entries a year, and it makes it clean to label these entries to the month that it corresponds to.

The start dates that start on say January 1st are easy to see. They would be linked to January. However a data point that has a start date on January 31st to March 1st creates complications. I can't link it using the starting date cell. I have to use both the start and end date cells. The code you gave me managed to accurately give me the month it would correspond to if that scenario occurs.

The next scenario that creates issues is from the sample posted above. With the start and end date in the middle of a month there is no obvious month. I think this is best suited to have the first cell in this table register a month and then the cells under it go to the next month while confirming that it is a valid month within the date range.
 
Upvote 0
Well, that is exactly what that formula does. However, in the example you provide, 2/14/2009 to 3/16/2009 there are 15 days in February 14-28 and 16 days in March 1-16. This makes March have one extra day and is why it shows as Mar.

For the scenario you describe, the date range 2/14/2009 to 3/15/2009 would have 15 days in both Feb and Mar and the output will show as Feb as you requested.
Let me know if I am totally missing something.

ADDITION:
Also, 2/14/2008 to 3/16/2008 = FEB because 2008 was a leap year and there are 16 days in FEB that year.
 
Last edited:
Upvote 0
Sadly I can't change the dates of the months. These months are more of titles that are used to calculate means and other statistical data. By having a situation in which 2 months appear within the same year it will throw off the data. It is relatively the same dates from one year to the next.

My thought on how to approach this is to do as followed:

Recognize if a month is in the cell above.

If there isn't a month above it will calculate the month from our original equation. (This is for row #1)

If there is a month above it, it will take that month and go to the next month. (For example cell above is Jan, so it will want to set the cell to Feb)
Afterwards, it will register all the months that have more then 12 days active in the start and end date range. (Say the range is 2/14/2009 to 3/16/2009. This will see Feb and Mar)

If the start and end date has the month as an available option it will set it to that month. (And(Feb, Or(Feb, Mar)), Feb)



I'm slightly grasping how to do this, but I'm not too sure on how to handle the recognition of months within the range.
 
Upvote 0
Like this?

=IF(A10="",IF((C11+((D11-C11)/2)=0),"",TEXT(C11+((D11-C11)/2),"MMM")),TEXT(EOMONTH(DATEVALUE(A10&"1900"),1),"MMM"))

It is a bit convoluted, but I believe it will do what you just said.

Although honestly, I am confused by this:
Afterwards, it will register all the months that have more then 12 days active in the start and end date range. (Say the range is 2/14/2009 to 3/16/2009. This will see Feb and Mar)

If the start and end date has the month as an available option it will set it to that month. (And(Feb, Or(Feb, Mar)), Feb)
 
Last edited:
Upvote 0
Or just put -1 in BiocideJ's formula

Below give Feb for 2-14-2009 - 3-16-2009 :

Code:
=TEXT(C2+((D2-C2)/2-1),"MMM")
 
Upvote 0
@platonic567

As much as I wish I could use that, I have over 16,000 data points... I rather not be spending all my time changing it manually for the occasional error.

@BiocideJ

So I got it working thanks to your formula. I appreciate your help. I need to get a better grasp to be able to think and create these formulas a little faster.

Thanks again. You were very helpful.
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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