Sorting by chronological not alphabetical months in GROUPBY.

Shortmeister1

Board Regular
Joined
Feb 19, 2008
Messages
212
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
  6. 2003 or older
Platform
  1. Windows
Merry Christmas all

My sample table looks like this:


Date
16/05/2024
07/06/2024
11/06/2024
21/06/2024
01/07/2024
13/07/2024
23/07/2024
28/09/2024
29/09/2024


A small formula using the new GROUPBY function.
Excel Formula:
=GROUPBY(
TEXT(tblV[Date],"mmm-yy"),
TEXT(tblV[Date],"mmm-yy"),
COUNTA,0,0)

The problem with this is that April becomes the first month in the year, whereas I want the year to start with January.

Easy to do in a Pivot table, but surely shouldn't be too difficult to replicate it using GROUPBY? (I don't want to create a helper column)

Any takers?

Thanks
Martin
 

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,)
How about
Excel Formula:
=DROP(GROUPBY(HSTACK(EOMONTH(+Tblv,0),TEXT(Tblv[Date],"mmm-yy")),TEXT(Tblv[Date],"mmm-yy"),COUNTA,0,0),,1)
Or
Excel Formula:
=GROUPBY(EOMONTH(+Tblv,0),TEXT(Tblv[Date],"mmm-yy"),COUNTA,0,0)
and format the 1st col as mmm-yy
 
Upvote 0
Solution
I added 2 dates to your table.
Try either of the following

T202412a.xlsm
ABCDEFGH
1
2Date
316-May-242401124011
47-Jun-242404124041
511-Jun-242405124051
621-Jun-242406324063
71-Jul-242407324073
813-Jul-242409224092
923-Jul-24Total11Total11
1028-Sep-24
1129-Sep-24
125-Jan-24
134-Apr-24
4d
Cell Formulas
RangeFormula
D3:E9D3=LET(d,TEXT(Tblv[Date],"yymm"),GROUPBY(d,--d,COUNT))
G3:H9G3=LET(d,TEXT(Tblv[Date],"yymm"),GROUPBY(d,d,COUNTA))
Dynamic array formulas.
 
Upvote 0
What is your expected result?
If you do not want to show months with 0, filter the results.

T202412a.xlsm
ABCDEFG
1
2Date
316-May-2424011Jan1
47-Jun-2424041Feb0
511-Jun-2424051Mar0
621-Jun-2424063Apr1
71-Jul-2424073May1
813-Jul-2424092Jun3
923-Jul-24Total11Jul3
1028-Sep-24Aug0
1129-Sep-24Sep2
125-Jan-24Oct0
134-Apr-24Nov0
14Dec0
15
4d
Cell Formulas
RangeFormula
C3:D9C3=LET(d,TEXT(Tblv[Date],"yymm"),GROUPBY(d,d,COUNTA))
F3:G14F3=HSTACK(Months,LET(d,Tblv[Date],IFNA(VLOOKUP(SEQUENCE(12),GROUPBY(MONTH(d),d,COUNT),2,0),0)))
Dynamic array formulas.
 
Upvote 0
Another variation could be:

Excel Formula:
=LET(
    a, GROUPBY(EOMONTH(+tblV[Date],0),tblV[Date],ROWS,0,0),
    HSTACK(TEXT(TAKE(a,,1),"mmm-yy"),DROP(a,,1))
)

Note: the values argument of GROUPBY can simply be tblV[Date] in this case (it is unnecessary to perform an additional TEXT calculation on the entire column again).

Merry Christmas!
 
Upvote 0
I like djclements post #5

Included are versions that I had prepared.
The second option uses helper named arrays for the month numbers and the month short names

T202412a.xlsm
ABCDEFG
1
2Date
316-May-2424012Jan2
47-Jun-2424041Apr1
511-Jun-2424051May1
621-Jun-2424063Jun3
71-Jul-2424073Jul3
813-Jul-2424092Sep2
923-Jul-24Total1212
1028-Sep-24
1129-Sep-24
125-Jan-24
134-Apr-24
1420-Jan-24
15
4d
Cell Formulas
RangeFormula
C3:D9C3=LET(d,TEXT(Tblv[Date],"yymm"),GROUPBY(d,d,COUNTA))
F3:G9F3=LET(a,LET(d,MONTH(Tblv[Date]),GROUPBY(d,d,COUNTA)),HSTACK(XLOOKUP(CHOOSECOLS(a,1),Mons,Months,"",0),CHOOSECOLS(a,2)))
Dynamic array formulas.
 
Upvote 0
Another choice
Custom format column C to your preference; I used "mmm".



T202412a.xlsm
ABCD
1
2Date
316-May-24Jan2
47-Jun-24Apr1
511-Jun-24May1
621-Jun-24Jun3
71-Jul-24Jul3
813-Jul-24Sep2
923-Jul-24Total12
1028-Sep-24
1129-Sep-24
125-Jan-24
134-Apr-24
1420-Jan-24
4d
Cell Formulas
RangeFormula
C3:D9C3=LET(d,Tblv[Date],GROUPBY(d-DAY(d)+1,d,COUNT))
Dynamic array formulas.
 
Upvote 0
Thanks for all the replies guys. Really appreciated.

Surprising that MS didn't add different kinds of sort to this functionality, but definitely have some hacks to work with.

Cheers!
 
Upvote 0
=GROUPBY(EOMONTH(+Tblv,0),TEXT(Tblv[Date],"mmm-yy"),COUNTA,0,0)
Dear Mr Fluff

One question that's puzzling me. Why the + symbol in EOMONTH? I can see that it errors without it, but I can't see why.

Cheers
 
Upvote 0
EOMONTH does not like being given a range, but is happy with an array & the + sign converts the range into an array.
 
Upvote 0

Forum statistics

Threads
1,225,888
Messages
6,187,648
Members
453,434
Latest member
fattyhuman

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