Dynamic Sort of =FILTER results

TheSubject

New Member
Joined
Feb 16, 2016
Messages
23
Hi! As the name suggests, looking for help dynamically sorting data from a filter formula.

See below attached mini sheet.

Data is just an example, but in this example, column J (3pm) my venue is fullest, but the list provided is in order of when it was entered as per the source list. I need to rearrange dynamically according to the headcount of the booking (column AA) vs the number of seats at each table written in column A in the last number

I don't even know where to start! Google has provided non-dynamic approaches!

bookings.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1
2CAPACITYDate20/04/2021
3Times11:0011:3012:0012:3013:0013:3014:0014:3015:0015:3016:0016:3017:0017:3018:0018:3019:0019:3020:0020:3021:0021:30Shortlist
4T1 - 6daveEmptyEmptyEmptyEmptyEmptyJaneEmptyTomEmptyEmptyEmptyEmptyEmptyDavidEmptyLazarusEmptyEmptyEmptyEmptyEmptyNameHeadcountArrivalDeparture
5T2 - 4****Tom615:0017:00
6T3 - 2DARREN****615:0021:00
7T4 - 6JAMESLazarus619:0021:00
8T5 - 4TonyDanny620:0022:00
9T6 - 6ElizaJane414:0018:00
10T7 - 6JimDavid118:0020:00
11T8 - 4sarahDARREN115:0017:00
12T9 - 4lizJAMES115:0017:00
13T10 - 4gerardTony515:0017:00
14T11 - 4hubertEliza615:0017:00
15T12 - 4james115:0017:00
16T13 - 4Jim615:0017:00
17sarah215:0017:00
18liz115:0017:00
19gerard315:0017:00
20hubert315:0017:00
21dave311:0013:00
Sheet1
Cell Formulas
RangeFormula
B4:I4,K4:W4,J4:J14B4=UNIQUE(IFERROR(FILTER($Z:$Z,$AB:$AB=B$3,"Empty"),""))
Z5:Z21Z5=FILTER(AG:AG,AH:AH=$AA$2)
AA5:AA21AA5=IF(Z5="","",INDEX(AI:AI,MATCH(Z5,AG:AG,0)))
AB5:AB21AB5=IF(Z5="","",INDEX(AJ:AJ,MATCH(Z5,AG:AG,0)))
AC5:AC21AC5=IF(Z5="","",INDEX(AL:AL,MATCH(Z5,AG:AG,0)))
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:W16Cell Valuecontains "Empty"textNO
Cells with Data Validation
CellAllowCriteria
AA1:AA21Custom=COUNTIF(AS2:BO501,">58")=0



Thank you so much!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It took me a while to figure out what you're asking, but I think I have it. I had to sort the table column by capacity. Also, the formulas use the dynamic array functions, but they don't Spill. You'll have to drag the formulas down the column. But consider this:

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1
2CAPACITYDate4/20/2021
3Times11:00:0011:30:0012:00:0012:30:0013:00:0013:30:0014:00:0014:30:0015:00:0015:30:0016:00:0016:30:0017:00:0017:30:0018:00:0018:30:0019:00:0019:30:0020:00:0020:30:0021:00:0021:30:00Shortlist
4T3 - 2        DARREN     David       NameHeadcountArrivalDeparture
5T2 - 4dave     Jane JAMES             Tom615:0017:00
6T5 - 4        sarah             ***615:0021:00
7T8 - 4        liz             Lazarus619:0021:00
8T9 - 4        gerard             Danny620:0022:00
9T10 - 4        hubert             Jane414:0018:00
10T11 - 4                      David118:0020:00
11T12 - 4                      DARREN115:0017:00
12T13 - 4                      JAMES115:0017:00
13T1 - 6        Tom       Lazarus     Tony515:0017:00
14T4 - 6        Tony             Eliza615:0017:00
15T6 - 6        Eliza             james115:0017:00
16T7 - 6        Jim             Jim615:0017:00
17sarah215:0017:00
18        Not enough tables             liz115:0017:00
19gerard315:0017:00
20hubert315:0017:00
21dave311:0013:00
Sheet1
Cell Formulas
RangeFormula
B4:W16B4=IFERROR(INDEX(FILTER($Z$5:$Z$21,($AA$5:$AA$21<=RIGHT($A4)+0)*(COUNTIF(B$3:B3,$Z$5:$Z$21)=0)*($AB$5:$AB$21=B$3)),1),"")
B18:W18B18=IFERROR(IF(COUNTIF(B4:B16,"?*")<>ROWS(UNIQUE(FILTER($Z$5:$Z$21,($AB$5:$AB$21=B3)))),"Not enough tables",""),"")


I added the row 18 formula to indicate there aren't enough tables. At 15:00, there were 5 parties needing a table of 6 when only 5 were available. Also, depending on how long the table is used, there could be an issue if another party came in at 15:30 needing a table.

But take a look and see what you think.
 
Upvote 0
Solution
An alternative method, using the same principle as @Eric W in that the table column is sorted by capacity, I've also split the table and capacity into 2 separate columns.

XL2BB wouldn't let me post the entire thing as it 'exceeds the limit that can be posted on the forum' even though it is the same range, so I'm guessing the longer formulas pushed it over the edge. The snippet below should be enough to demonstrate the theory that I was working on, columns Z:AC are identical to the original sample with the exceptions of 1 name change so that the profanity filter didn't cause problems, and the headcount for Gerard increased to 6 in order to test the 'unallocated' formula in the bottom row. (I started with conditional formatting on the names in column z to highlight them as they were added to the table, but Eric's idea seems better).

One point to note, neither Eric or myself have allowed for identical names in column Z, the formulas are not case sensitive so JAMES and james are taken as the same person. There are functions that can allow for identical names in the source list, but with everything else that is needed I don't see them being a realistic option here.

There is likely room for improvement, but I think that you have 2 good options to explore.

Cell Formulas
RangeFormula
C4:P16,C17C4=IFERROR(IF(XLOOKUP(B4,$Z$5:$Z$21,$AC$5:$AC$21,0)>C$3,B4,INDEX(SORT(FILTER($Z$5:$AC$21,($AA$5:$AA$21<=$B4)*($AB$5:$AB$21=C$3)*(COUNTIF($B$4:B$16,$Z$5:$Z$21)=0)*(COUNTIF(C$3:C3,$Z$5:$Z$21)=0)),{2,3,4},{-1,1,-1}),COUNT(FILTER($B$3:$B3,($B4<$B$3:$B3)*IF(B$3:B3="",TRUE,B$3:B3<>C$3:C3),""))+1,1)),"")
B17B17=MAX($AA$5:$AA$21)
D17:P17D17=IFERROR(TEXTJOIN(", ",1,INDEX(SORT(FILTER($Z$5:$AC$21,($AA$5:$AA$21<=$B17)*($AB$5:$AB$21=D$3)*(COUNTIF($B$4:B$16,$Z$5:$Z$21)=0)*(COUNTIF(D$3:D16,$Z$5:$Z$21)=0)),{2,3,4},{-1,1,-1}),0,1)),"")
 
Upvote 0
Thanks, both of you - I'm still working on it, but you've given me a lot to go on!
@jasonb75 I like you're "unallocated" as opposed to just not enough tables, so will try to work that in from what I have from @Eric W already.

I've modified Eric W's formula so (apart from the opening slot at 11:00) they now read:

=IF(ISERROR(F11),(INDEX(FILTER($Z$5:$Z$21,($AA$5:$AA$21<=RIGHT($A11)+0)*(COUNTIF(G$3:G10,$Z$5:$Z$21)=0)*($AB$5:$AB$21=G$3)),1)),IF(INDEX($AC:$AC,MATCH(F11,$Z:$Z,0))>G$3,F11,(INDEX(FILTER($Z$5:$Z$21,($AA$5:$AA$21<=RIGHT($A11)+0)*(COUNTIF(G$3:G10,$Z$5:$Z$21)=0)*($AB$5:$AB$21=G$3)),1))))

Which gives peoples stay length, and a ton of errors instead of blanks, but I've made a front sheet, that removes the million errors that pop up but otherwise equals it. Maybe a little less elegant, but I'm learning!!

Of course, I emailed this to myself at work and opened my macbook and it didn't work!! But I'll try to update excel or just use it on the office PC if not.
 
Upvote 0
It occurred to me that you could shorten the way you rewrote your formula, like:

Book2
ZAAABAC
1
2Date4/20/2021
3Shortlist
4NameHeadcountArrivalDeparture
5Tom615:0017:00
6Richard615:0021:00
7Lazarus615:0021:00
8Danny620:0022:00
9Jane414:0018:00
10David118:0020:00
11DARREN115:0017:00
12JAMES115:0017:00
13Tony515:0017:00
14Eliza615:0017:00
15james115:0017:00
16Jim615:0017:00
17sarah215:0017:00
18liz115:0017:00
19gerard315:0017:00
20hubert315:0017:00
21dave311:0013:00
Sheet1



Cell Formulas
RangeFormula
B4:W16B4=IFERROR(TEXTJOIN(", ",1,TEXT(INDEX(FILTER($Z$5:$AC$21,($AA$5:$AA$21<=RIGHT($A4)+0)*(COUNTIF(B$3:B3,$Z$5:$Z$21&"*")=0)*($AB$5:$AB$21=B$3)),1,{1,4}),"h:mm;@")),"")
B18:W18B18=IFERROR(TEXTJOIN(", ",1,INDEX(FILTER($Z$5:$AC$21,($AB$5:$AB$21=B$3)*(COUNTIF(B$4:B$16,$Z$5:$Z$21&"*")=0)),0,1)),"")
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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