# 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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

#### Joe4

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
62
Replies
10
Views
385
Replies
33
Views
710
Replies
5
Views
107
Replies
6
Views
203

1,127,610
Messages
5,625,797
Members
416,138
Latest member
Pizzaman22

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

### Which adblocker are you using?

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

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