Is there a way to sort a column on just the date portion of a day+time field?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
Consider this table containing 7 items that each have a Last Used field and a Rating field.

Sorting.xlsx
CDE
4ItemLast UsedRating
5A8/28/23 14:33 91
6B8/27/23 18:25 81
7C8/28/23 08:21 89
8D8/27/23 09:35 78
9E8/28/23 17:53 83
10F8/27/23 11:22 95
11G8/28/23 07:02 77
Dates


I would like to sort the table by Last Used (oldest to newest) and then by Rating (high to low). If I do that, I get this:

Sorting.xlsx
CDE
4ItemLast UsedRating
5D8/27/23 09:35 78
6F8/27/23 11:22 95
7B8/27/23 18:25 81
8G8/28/23 07:02 77
9C8/28/23 08:21 89
10A8/28/23 14:33 91
11E8/28/23 17:53 83
Dates


In this sort, the Rating field is irrelevant because no two Last Used values are identical. There are many that happened on the same date, but at different times. I only want the sort to take into account the date portion of the Last Used field.

I can get the result I want by adding a helper column with just the date portion of the Last Used field.

Sorting.xlsx
CDEF
4ItemLast UsedRatingDate
5F8/27/23 11:22 958/27/23 00:00
6B8/27/23 18:25 818/27/23 00:00
7D8/27/23 09:35 788/27/23 00:00
8A8/28/23 14:33 918/28/23 00:00
9C8/28/23 08:21 898/28/23 00:00
10E8/28/23 17:53 838/28/23 00:00
11G8/28/23 07:02 778/28/23 00:00
Dates
Cell Formulas
RangeFormula
F5:F11F5=ROUNDDOWN([@[Last Used]],0)


Is there a way I can sort this table and get this result without the use of a helper column?
 
You can do it as below but by using a formula you will still end up with a duplicate of your original table:
Book1
ABCDEFG
1ItemLast UsedRatingItemLast UsedRating
2F27/08/2023 11:2295F27/08/2023 11:2295
3A28/08/2023 14:3391B27/08/2023 18:2581
4C28/08/2023 08:2189D27/08/2023 09:3578
5E28/08/2023 17:5383A28/08/2023 14:3391
6B27/08/2023 18:2581C28/08/2023 08:2189
7D27/08/2023 09:3578E28/08/2023 17:5383
8G28/08/2023 07:0277G28/08/2023 07:0277
Sheet1
Cell Formulas
RangeFormula
E2:G8E2=SORTBY(Table1,TRUNC(Table1[Last Used],0),1,Table1[Rating],-1)
Dynamic array formulas.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You can do it as below but by using a formula you will still end up with a duplicate of your original table:
Hmmm... Interesting. I'll take a look, but I think the Power Query will be my best option. Thanks
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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