Best way to sort a table by month & day ignoring year

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,687
Office Version
  1. 365
Platform
  1. Windows
I have a table of family members with their dates of birth. I would like to sort it by month and day ignoring the year. Here is a sample table. The only way I could think of was to add a helper column with just the month and day. Is there a better way that does not require the helper column?

Christmas & Birthday Candy.xlsx
CDE
4NameDoBm/dd
5Joe1/21/198001.21
6Sally2/03/194402.03
7Billy5/24/197805.24
8Nancy8/15/195508.15
9Henry10/10/199410.10
10Linda12/17/201212.17
Sheet1
Cell Formulas
RangeFormula
E5:E10E5=TEXT([@DoB],"mm.dd")
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this

in Cells "C2"
Excel Formula:
=SORTBY(TEXT(B2:B7,"MM/DD"),MONTH(B2:B7),1,DAY(B2:B7),1)

in cells "E2"
Excel Formula:
=SORTBY(HSTACK(A2:A7,TEXT(B2:B7,"mm/dd")),MONTH(B2:B7),1,DAY(B2:B7),1)

1706859052724.png
 
Last edited:
Upvote 0
Try this

in Cells "C2"
Excel Formula:
=SORTBY(TEXT(B2:B7,"MM/DD"),MONTH(B2:B7),1,DAY(B2:B7),1)

in cells "E2"
Excel Formula:
=SORTBY(HSTACK(A2:A7,TEXT(B2:B7,"dd/mm")),MONTH(B2:B7),1,DAY(B2:B7),1)

View attachment 106189
Hmmm... What I see in the quote above in my reply is quite different from what I see in your reply.

It looks like your solution also required the helper column, no?
 
Upvote 0
Hmmm... What I see in the quote above in my reply is quite different from what I see in your reply.

It looks like your solution also required the helper column, no?
it doesn't need a helper column just convert the date to an array(MM/DD) then sort it by Month & Day.
 
Upvote 0
Two quick thoughts and I hope you receive some alternatives.
The first requires the helper column and the sort may not be appropriate.

Kim 202312.xlsx
CDE
1
2
3Sorted by Column E
4NameDoBm/dd
5Joe21-Jan-80121
6Sally03-Feb-44203
7Billy24-May-78524
8Nancy15-Aug-55815
9Henry10-Oct-941010
10Linda17-Dec-121217
11
12Formula solution
13Joe21-Jan-80
14Sally03-Feb-44
15Billy24-May-78
16Nancy15-Aug-55
17Henry10-Oct-94
18Linda17-Dec-12
1dd
Cell Formulas
RangeFormula
E5:E10E5=--TEXT(D5,"mmdd")
C13:C18C13=XLOOKUP(D13:D18,$D$5:$D$10,$C$5:$C$10)
D13:D18D13=SORTBY(D5:D10,--TEXT(D5:D10,"mmdd"))
Dynamic array formulas.
 
Upvote 0
try the following

Kim 202312.xlsx
BCD
20Formula solutionDOB
21Joe21-Jan-80
22Sally03-Feb-44
23Billy24-May-78
24Nancy15-Aug-55
25Henry10-Oct-94
26Linda17-Dec-12
1dd
Cell Formulas
RangeFormula
C21:D26C21=SORTBY(C5:D10,--TEXT(D5:D10,"mmdd"))
Dynamic array formulas.
 
Upvote 0
An alternative with Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DoB", type date}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Text Before Delimiter", each Text.BeforeDelimiter(Text.From([DoB], "en-US"), "/", {0, RelativePosition.FromEnd}), type text),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Text Before Delimiter",{"DoB"})
in
    #"Removed Columns"
 
Upvote 0
The formula can work with the text =SORTBY(C5:D10,TEXT(D5:D10,"mmdd")) or with Table

Kim 202312.xlsx
CDEFG
1
2
3
4NameDOB
5Billy24-May-78Joe21-Jan-80
6Henry10-Oct-94Sally03-Feb-44
7Joe21-Jan-80Billy24-May-78
8Linda17-Dec-12Nancy15-Aug-55
9Nancy15-Aug-55Henry10-Oct-94
10Sally03-Feb-44Linda17-Dec-12
11
1dd
Cell Formulas
RangeFormula
F5:G10F5=SORTBY(Table2,TEXT(Table2[DOB],"mmdd"))
Dynamic array formulas.
 
Upvote 0
Two quick thoughts and I hope you receive some alternatives.
The first requires the helper column and the sort may not be appropriate.

Kim 202312.xlsx
CDE
1
2
3Sorted by Column E
4NameDoBm/dd
5Joe21-Jan-80121
6Sally03-Feb-44203
7Billy24-May-78524
8Nancy15-Aug-55815
9Henry10-Oct-941010
10Linda17-Dec-121217
11
12Formula solution
13Joe21-Jan-80
14Sally03-Feb-44
15Billy24-May-78
16Nancy15-Aug-55
17Henry10-Oct-94
18Linda17-Dec-12
1dd
Cell Formulas
RangeFormula
E5:E10E5=--TEXT(D5,"mmdd")
C13:C18C13=XLOOKUP(D13:D18,$D$5:$D$10,$C$5:$C$10)
D13:D18D13=SORTBY(D5:D10,--TEXT(D5:D10,"mmdd"))
Dynamic array formulas.
How is your first example with the helper column different than my original solution?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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