Grouping by dates in Excel?

Copper Contributor

How do you group dates  that fall within specific date ranges? Is it by formula or by grouping by month, but the grouping won't work if you want an odd date range like from the 9th of one month to the 10th of the next month.

 

7 Replies

Hi @MMH11 

 

There are many ways to handle your query, If you have single range of date, then I would recommend you using IF function (You can add multiple criteria in IF function, but formula will become too complex). I'm attaching Excel Workbook with few examples with IF , VLOOKUP & XLOOKUP.

 

Hope this might be helpful. 

 

Snag_4666368.png

 

Regards, Faraz Shaikh | MCT, MIE, MOS Master, Excel Expert | www.ExcelExciting.com

 

@Faraz Shaikh  Sorry, I don't think I was very clear in my question. 

 

I have a list of employees with their work dates in a given year.  I want to insert a formula that indicates which period they fall in but it has to be a date from 15th to 14th of following month. So if the date is 01/05/2020 it should fall in the period 12/15/2019-01/14/2020. What formula would do this?
Employee     Work Date      PERIOD
John         01/05/2020         12/15/2019-01/14/2020
John         01/15/2020          01/15/2020-02/14/2020
John         02/05/2020          01/15/2020-02/14/2020
John         03/06/2020          02/15/2020-03/14/2020

Create a help table with border-dates and Group names. Something like:

01/01/2020

- 01/01/2020

01/15/2020

01/01/2020 - 01/15/2020

02/01/2020

01/15/2020 - 02/01/2020

03/01/2020

02/01/2020 - 03/01/2020

04/01/2020

03/01/2020 - 04/01/2020

05/01/2020

04/01/2020 - 05/01/2020

06/01/2020

05/01/2020 - 06/01/2020

07/01/2020

06/01/2020 - 07/01/2020

08/01/2020

07/01/2020 - 08/01/2020

09/01/2020

08/01/2020 - 09/01/2020

10/01/2020

09/01/2020 - 10/01/2020

11/01/2020

10/01/2020 - 11/01/2020

12/01/2020

11/01/2020 - 12/01/2020

 

Then you can use Match/index with match_type 1 or vlookup with “approximate match”=true.

If your support-table is in H1:I13 something like this should word:

=Vlookup(B1,H1:I13,2,1)

(Quick and Dirty translation. Play around)

 

 

@MMH11 Alternatively, use one of the solutions in the attached workbook. The first one determines both the start and the end of the period, based on the start day (15 in your case). It uses the fairly neat EOMONTH function. The second option combines start and end of the period into one text string.

Cell B1 contains the start day of your period and I gave it the name "from".

 

<ed>sorry. i missed Rinys last  answere. This is probably a duplicate.</ed>


Generic formula. Same reservation as before. It’s an untested translation.
=TEXT(EOMONTH(B1,-2)+15,"MM/DD/YYYY")&"-"&TEXT(EOMONTH(B1,-1)+14,"MM/DD/YYYY")

@Deleted  @Riny_van_Eekelen  @Faraz Shaikh 

Would you know why Excel can't do this period automatically when selecting Grouping by month in a pivot table? Maybe there is a period option?

@MMH11 Well, I guess Excel uses standard periods such as calendar weeks, months, quarters and years. And then you can group by x number of days (like 28 days = 4 weeks). Grouping from the 15th of one month till the 14th of the next may be 30 days one month, 31 days another and sometimes 28 or 29 days. So, thats not a fixed number of days either. But why Excel can't do it by default, I can't tell. Perhaps, that's why they came up with EOMONTH.