# IFS function with dates

#### BigGee

##### New Member
Hello,
I am trying to interrogate a spreadsheet to return a month number if a date falls between the first and start of a month. I understand this would be easy using MONTH function but as my data covers several years I want to allocate a month and year number.

I have the IF function for a single entry which works correctly
=IF(AND(B4>=DATEVALUE("01/05/2020"),B4<=DATEVALUE("31/05/2020")),"5/20","NO")

but when I try to convert to IF to an IFS function by adding in other months then I cannot get it to work.

=IFS(AND(B5>=DATEVALUE("01/05/2020"),B5<=DATEVALUE("31/05/2020")),"5/20",B5>=DATEVALUE("01/04/2020"),B5<=DATEVALUE("30/04/2020"),"4/20",B5>=DATEVALUE("01/03/2020"),B5<=DATEVALUE("31/03/2020"),"3/20")
returns me a correct response for May, a TRUE value for an April date and #VALUE for March

Could anyone either
1. tell me where I am going wrong, or
2. show me an easier way?

### Excel Facts

If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

#### Joe4

##### MrExcel MVP, Junior Admin
I think you are missing the "AND" in the formula where you are trying to check the second date range.

#### BigGee

##### New Member
I think you are missing the "AND" in the formula where you are trying to check the second date range.
Adding in an AND function as below
=IFS(AND(B6>=DATEVALUE("01/05/2020"),B6<=DATEVALUE("31/05/2020")),"5/20",AND(B6>=DATEVALUE("01/04/2020"),B6<=DATEVALUE("30/04/2020"),"4/20"),AND(B6>=DATEVALUE("01/03/2020"),B6<=DATEVALUE("31/03/2020"),"3/20"))
May works but now April and March also return a #VALUE

Why not just use
=MONTH(B6)&"/20"

#### drsarao

##### Well-known Member

Since data is spanning several years:
=MONTH(B6) & "/" & YEAR(B6)

thanks
drsarao
works perfectly

#### drsarao

##### Well-known Member

You are welcome!
I only added to Fluff's insight.

#### jasonb75

##### Well-known Member
2. show me an easier way?
Maybe =B6 formatted as m/yy or =TEXT(B6,"m/yy")

#### RoryA

##### MrExcel MVP, Moderator
Or TEXT(B6,"m/yy")

Replies
5
Views
122
Replies
10
Views
433
Replies
33
Views
785
Replies
5
Views
131
Replies
6
Views
237

1,130,357
Messages
5,641,630
Members
417,228
Latest member
BarriCA

### 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?

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