Single Formula to Extract Rows and Reorder in New Table v2

M10Ant

New Member
Joined
Dec 30, 2021
Messages
36
Office Version
  1. 365
Platform
  1. Windows
I have a source Order Table that records the date customers placed an order, when the order was dispatched and whether the order was a web order or not. This is shown in the left-most column below.

My aim is to have a report table that shows only all Web Orders, sorting in ascending order of the Order Dispatched date and listing the customer name. This is shown in the middle table below.

Excel-Cheat-Sheet.xlsx
BCDEFGHIJKL
8Source Order Table DataReport Table v1Report Table v2
9Order PlacedCustomerOrder DispatchedWeb Order?Order DispatchedCustomerSource ROW #Order DispatchedCustomer
1001/05/2022 15:00John Simpson03/06/2022Y11/05/2022Bill Green711/05/2022Bill Green
1117/06/2022 08:45Carol Walker24/06/2022N12/05/2022Jason Millbank312/05/2022Jason Millbank
1211/05/2022 16:20Jason Millbank12/05/2022Y19/05/2022Evan Tompson619/05/2022Evan Tompson
1322/06/2022 12:10Steven Jones24/06/2022Y03/06/2022John Simpson103/06/2022John Simpson
1407/05/2022 15:55Paul Cragg14/05/2022N08/06/2022Sue Evans1008/06/2022Sue Evans
1516/07/2022 10:23Evan Tompson19/05/2022Y08/06/2022John Deen1108/06/2022John Deen
1610/05/2022 20:20Bill Green11/05/2022Y24/06/2022Steven Jones424/06/2022Steven Jones
1719/07/2022 21:10Henry Down21/07/2022Y21/07/2022Henry Down821/07/2022Henry Down
1819/07/2022 21:10Katherine Day27/07/2022N     
1905/05/2022 16:08Sue Evans08/06/2022Y     
2006/06/2022 11:05John Deen08/06/2022Y     
7 (2)
Cell Formulas
RangeFormula
G10:G20,K10:K20G10=IFERROR(AGGREGATE(15,6,tblSrcOrders[Order Dispatched]/(tblSrcOrders[Web Order?]="Y"),ROW([@[Order Dispatched]])-ROW(tblReportv1[[#Headers],[Order Dispatched]])),"")
H10:H20H10=IFERROR(INDEX(tblSrcOrders[Customer],AGGREGATE(15,6,ROW(tblSrcOrders[Customer])/(tblSrcOrders[Web Order?]="Y")/(tblSrcOrders[Order Dispatched]=G10),COUNTIF(G$10:G10,G10))-ROW(tblSrcOrders[[#Headers],[Web Order?]])),"")
J10:J20J10=IF(ROWS(tblReportv2[[#Headers],[Source ROW '#]]:[@[Source ROW '#]])-1<=(COUNTIF(tblSrcOrders[Web Order?],"Y")), IFERROR(AGGREGATE(15,6,ROW(tblSrcOrders[Customer])/(tblSrcOrders[Web Order?]="Y")/(tblSrcOrders[Order Dispatched]=[@[Order Dispatched]]),COUNTIF(tblReportv2[[#Headers],[Order Dispatched]]:[@[Order Dispatched]],[@[Order Dispatched]]))-ROW(tblSrcOrders[[#Headers],[Web Order?]]),""),"")
L10:L20L10=IF([@[Source ROW '#]]<>"", INDEX(tblSrcOrders,[@[Source ROW '#]],2), "")
Named Ranges
NameRefers ToCells
'7 (2)'!tblRptHelper='7 (2)'!$J$10L10, J11:J20


Firstly a big thank you to Jasonb75 who provided me with the formulas to use in the report table which provides the data needed and is a brilliant solution. (It also took my hours to understand being such an Excel beginner!). Link to original post here: Formula to Extract Rows and Reorder in new Table

The table in the middle above relies on the formula of two columns to get the row positions of all relevant rows, and sort in ascending order of Order Dispatched dates. Referring to the columns in that middle reporting table:
  • Order Dispatched: Calculates the array of relevant dates, ordered in ascending order and including all duplicate dates where they exist, and pulls out the array entry relevant for the current row
  • Customer: Uses the calculated Order Dispatched date in the report table to return the relevant Customer entry corresponding to it from the source table and also takes into account duplicate dates

The solution works great, but intending to use this on a larger data set with more columns to report on, I'm trying to see if there is a single formula I can use in a "helper" column at the start of the report table that will return the row number of the relevant row from the source table column in the report table. This would enable me to use a simple =INDEX(range, row_num) formula on any columns I need to include in the report table, using the calculated row number in the Helper column in the row_num argument to return the relevant entry.

The third table above gives an idea of what I'm aiming for. Whilst the table still provides the required data, the issue is that the helper column still relies on the formula in another column to get the row positions (Order Dispatched column in that same report table). I'm hoping there is a single formula I can use in the helper column to do this. Most likely somehow a combination of the two formulas.
 
Hi Eric

Thanks for the explanation. It's an ingenious solution! I see the SORT function also ensures duplicates dates are not missed out, removing the need for using the SMALL function to cycle through duplicate dates and take them into consideration. So pleased this has gotten me over a big hurdle in my spreadsheet and can now progress further with it. Thanks very much for your time helping me with this Eric.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Mainly for my own benefit and to help me understand it, I've gone through and elaborated on Eric's explanation of SOURCE ROW formula. Just in case it helps anyone else.

[SOURCE ROW] value is calculated as follows:

SEQUENCE(ROWS(tblSrcOrders)) returns an array of numbers starting and one and incrementing by 1 for as many rows as there are in the source table. This effectively assigns each row in the table a unique row number.

tblSrcOrders[Dispatched] returns an array consisting of the [Dispatched] value of each row in the source table.

Both of these one-dimensional (1-column) arrays are then combined together into a two-dimensional array via CHOOSE({1,2},...)

The FILTER function is then applied to this two-dimensional array to filter all rows where [Web Order?] = "Y"

FILTER(...,tblSrcOrders[Web Order?]="Y")

This filtered two-dimensional array now effectively identifies the row numbers of each row in the source table where [Web Order?] = "Y", and lists the dispatch date associated with each. This filtered two-dimensional array then forms the array of the SORT function to sort the rows in ascending order. No parameters are specified for the SORT function other than the mandatory array. By default, the function will sort based on the contents of the first column of the array, which is the [Dispatched] date values, and in ascending order by default.

SORT(...)

The sorted, filtered array (which is still a two-dimensional array consisting of dispatch dates and their corresponding row numbers) then forms the array argument of an INDEX function.

INDEX(...,ROW([@[Source ROW]])-MIN(ROW([Source ROW]))+1,2)

This INDEX function serves to pull out the row numbers from the sorted, filtered two-dimensional array, starting at the first entry, and progressing through, one by done, for each successive row in the report table.

The calculation for the INDEX function's row_num argument is ROW([@[Source ROW]])-MIN(ROW([Source ROW]))+1. This returns a value starting at one and incrementing by one for each successive row in the report table. This ensures the INDEX function will return values from each successive row in the sorted, filtered array. The ROW([@[Source ROW]]) by itself will return the spreadsheet row number for the current row in the report table. To make the values start at one instead, the row number of the first data row of the source table is subtracted from this value and then 1 is added back on:
-MIN(ROW([Source ROW]))+1
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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