Sort as per earliest dates

soumen21

New Member
Joined
Aug 16, 2019
Messages
29
Hi,

I have a set of data as shown below


ValueCategoryDate
Red A3-Jun-19
YellowB8-Aug-22
Blue C10-Jun-20
GreenA12-Dec-19
BlackB12-Dec-21
PurpleC5-Jul-23
PinkA30-Dec-20
BrownA21-Nov-20
MagentaB5-Mar-19
OrangeA24-Jul-23
LimeA13-Feb-28


<colgroup><col><col><col></colgroup><tbody>
</tbody>

I want to sort it this way


Enter Category<A>Before 2020Between 2020-2022After 2023
ValueDateValueDateValueDate
Red3-Jun-19Brown21-Nov-20Orange24-Jul-23
Green12-Dec-19Pink30-Dec-20Lime13-Feb-28

<colgroup><col span="2"><col><col><col><col><col><col></colgroup><tbody>
</tbody>

Any formulas to use for sorting this way. Please help.

Regards
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try something like:
Code:
=IFERROR(INDEX($A$1:$A$12,AGGREGATE(15,6,(ROW($A$1:$A$12)/(($C$1:$C$12>=$G$1)*($C$1:$C$12<$H$1))),ROWS($A$1:$A2)-ROW($A$1))),"")
The formula looks horrible but it's not that complicated when you understand what it's doing. The heart of the formula is the INDEX that returns the actual value from the given range. I have my lookup table in A1:C12 and I'm using helper cells in G1 and H1 to give me the min and max values for the dates in the given bin. I'm using two dates for each bin but you could use just one date for the first and last bins.

I'm using AGGREGATE to return the row numbers for the INDEX. The 15 stands for SMALL and 6 tells AGGREGATE to skip error values. The array for the AGGREGATE is row number divided by a bunch of trues and falses.

I could've used a double negative to turn the booleans to ones and zeroes but since I've got two booleans I can simply multiply them with each other. The first one asks is the date in row bigger than my min date for my bin and the next one asks are you smaller than my max date. AGGREGATE returns a bunch of row numbers and errors but since it's ignoring the errors I'm getting just the row numbers.

The last bit of my formula (the ROWS-ROW bit) is just returning the k for the SMALL in AGGREGATE (1,2,3 etc). The outer IFERROR is there only to hide the error values you'd get if you asked for the 4 th smallest row number when there's only 3 values that match my criteria. If you've got a really big data set that you're doing this you'd better replace the IFERROR with a "IF rownumber > COUNTIF matches then return blank, otherwise do the calculation" because that way you'd get a way with a lot less calculations (IFERROR calculates each cell and only hides the errors).
 
Upvote 0
Hi Misca, Thanks for your reply. Could you please attach the spreadsheet where you tried this formula it would be helpful.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

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