TEXTJOIN as Text Date Sorts Incorrectly

Marcusreb

New Member
Joined
Nov 24, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I need some help please. I have column with names and a column with birthdays. I have created a dynamic calendar where I update the Month and Year and the formula will provide me a list of users with the birthday in that month and year. I need the formula to display in order but the dates are not sorting in correct order.

A1 = Name, B2 = Date, C1 = Month and D1 = Year
Formula is entered in E2 and the formula I have is =TEXTJOIN(CHAR(10),TRUE,(IF(TEXT(B2:B8,"MMMM YYYY")=C1&" "&D1,DAY(B2:B8)&" "&A2:A8,"")))

Matt
1/5/2023​
Dave
1/15/2023​
John
2/1/2023​
Tim
1/4/2023​
Beth
5/5/2023​
Paul
6/6/2023​

Outcome in need the dates to go in order, 4 Tim, 5 Matt, 15 Dave
5 Matt
15 Dave
4 Tim
 

Attachments

  • excel date sort issue.jpg
    excel date sort issue.jpg
    29.3 KB · Views: 11

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi, welcome to the forum! Here is one way you can try:

Book1
ABCDE
1NameDateJanuary2023
2Matt01/05/20234 Tim
3Dave01/15/20235 Matt
4John02/01/202315 Dave
5Tim01/04/2023
6Beth05/05/2023
7Paul06/06/2023
Sheet1
Cell Formulas
RangeFormula
E2:E4E2=LET(f,FILTER(A2:B7,TEXT(B2:B7,"mmmm yyyy")=C1&" "&D1),SORTBY(DAY(CHOOSECOLS(f,2))&" "&CHOOSECOLS(f,1),DAY(CHOOSECOLS(f,2))))
Dynamic array formulas.
 
Upvote 0
Hi & welcome to MrExcel.
How about
Excel Formula:
=LET(f,SORT(FILTER(A2:B8,TEXT(B2:B8,"mmmm yyyy")=C1&" "&D1),2),TEXTJOIN(CHAR(10),,DAY(TAKE(f,,-1))&" "&TAKE(f,,1)))
 
Upvote 0
Or try this

=TEXTJOIN(CHAR(10),1,IF(TEXT(B2:B7,"mmmmyyyy")=C1&D1,DAY(B2:B7)&" "&A2:A7,""))
 
Upvote 0
Or try this

=TEXTJOIN(CHAR(10),1,IF(TEXT(B2:B7,"mmmmyyyy")=C1&D1,DAY(B2:B7)&" "&A2:A7,""))
That doesn't sort the results as requested ..
I need the formula to display in order but the dates are not sorting in correct order.

@Marcusreb
Welcome to the MrExcel board!

Two more possibilities.
A variation of @Fluff's suggestion in E2 but also including handling the case case of no birthdays in the month.
A variation of @Phuoc's suggestion in F2 to ensure the dates are sorted (Phuoc's formula already handled the case of no birthdays in the month)

23 11 25.xlsm
ABCDEF
1NameDateJanuary2023
2Matt5/01/20234 Tim 5 Matt 15 Dave4 Tim 5 Matt 15 Dave
3Dave15/01/2023
4John1/02/2023
5Tim4/01/2023
6Beth5/05/2023
7Paul6/06/2023
Birthdays
Cell Formulas
RangeFormula
E2E2=TEXTJOIN(CHAR(10),,TAKE(SORT(FILTER(HSTACK(DAY(B2:B7)&" "&A2:A7,B2:B7),TEXT(B2:B7,"mmmmyyyy")=C1&D1,{"",1}),2),,1))
F2F2=LET(s,SORT(A2:B7,2),d,DROP(s,,1),TEXTJOIN(CHAR(10),1,IF(TEXT(d,"mmmmyyyy")=C1&D1,DAY(d)&" "&TAKE(s,,1),"")))
 
Upvote 0
Solution
Thank you for the responses much appreciated! I hope you all had a wonderful Thanksgiving!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,613
Members
452,661
Latest member
Nonhle

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