IFS function with dates

BigGee

New Member
Joined
Sep 8, 2020
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
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?

Thanks in advance
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,916
Office Version
  1. 365
Platform
  1. Windows
I think you are missing the "AND" in the formula where you are trying to check the second date range.
 

BigGee

New Member
Joined
Sep 8, 2020
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,541
Office Version
  1. 365
Platform
  1. Windows
Why not just use
=MONTH(B6)&"/20"
 
Solution

drsarao

Well-known Member
Joined
Sep 9, 2009
Messages
1,143
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

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

drsarao

Well-known Member
Joined
Sep 9, 2009
Messages
1,143
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,696
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Or TEXT(B6,"m/yy")
 

Watch MrExcel Video

Forum statistics

Threads
1,129,509
Messages
5,636,736
Members
416,938
Latest member
sc58963

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
Top