Forum Discussion
Excel_Struggler
Jul 19, 2024Copper Contributor
Cross sheet functionality and maintenance of the chronological order of a formula
Hi community,
I'm working on a formula that searches a range of cells and outputs it another range of cells where the criteria are based on matches on two dropdown menus which are dependent (Columns A and B)
Summarized the formula does the following:
1. Lookup: Excel searches for a selected item from a corresponding dropdown menu in column B.
2. Retrieving Previous Data: When a match is identified (two identical items), Excel should search the designated columns to retrieve the previously entered data for that item.
3. Order of Retrieval: If there are multiple entries for the same item, Excel will prioritize the nearest entry relative to a reference row (This means below the reference row, it should not search upwards). For example, if the reference row is 11, and there are entries in rows 16 and 21 for the same item, Excel should retrieve the data from row 16. (You can test this by either blanking dropdown cells in columns A and B, and it will switch to the output location)
=IF(B11="","",IFERROR(MAKEARRAY(5,3,LAMBDA(x,y,INDEX($G$1:$I$25,XLOOKUP(A11&B11,$A$5:$A$10&$B$5:$B$10,ROW($B$4:$B$9),,0,-1)+x,y))),""))
My problem is that I need this type of functionality across different sub-sheets so that when it starts searching in let's say week 1 (sheet 1) it will continue its search parameters in week 2 (sheet 2) and maintain the order of retrieval as mentioned in point 3 above. Essentially linking different sub-sheets together through one formula.
I attached a sample with annotations to explain how the formula functions and how I need it to work.
The solutions I can think of are;
1. Simplyfing the formula making it less stress intensive so that it would be possible to merge all sub-sheets into one big sheet
2. Creating a master sheet where one can perform lookups using the INDIRECT and MATCH functions
I'm not sure how to fully flesh out these ideas or of other solutions however.
Excel_Struggler The performance issue in this case is due to an array object (keyId) being passed to the lookup_array argument of XMATCH. If we spill the keyId results directly to a separate range in the worksheet, then reference the spill range in the lookup_array, it will drastically improve the calculation speed.
In the attached revision, I've defined the FILLDOWN function in Name Manager, moved the keyId formula to cell I6, and simplified the final formula in cell F6. I tested it to 16,000 rows and the calculation lag was virtually unnoticeable on my system (milliseconds). Hopefully it will perform well enough that you can avoid splitting the data into multiple sheets.
Cheers!
4 Replies
Sort By
- djclementsBronze Contributor
Excel_Struggler wrote:The solutions I can think of are:
1. Simplifying the formula making it less stress intensive so that it would be possible to merge all sub-sheets into one big sheetThis would be the way to go, in my opinion. Add another column with data validation to select the Week number, rather than having each week on a separate tab.
Regarding your description for "Order of Retrieval", I'm struggling to follow what you meant because your original formula doesn't seem to be doing exactly what you've described (to the best of my understanding). However, since your question doesn't appear to indicate that there's anything wrong with the formula, I made the assumption that it's already returning the desired results.
The following single-cell dynamic array formula returns the same results as your original formula(s), with the additional lookup criteria for week number:
=LET(r, 5, c, 3, data, WRAPROWS(TOCOL(D6:F25), r*c), array, A6:A25 & B6:B25 & C6:C25, keyId, FILTER(array, NOT(MOD(SEQUENCE(ROWS(array),, 0), r))), rowId, SEQUENCE(ROWS(keyId)), row_nums, MAP(keyId, rowId, LAMBDA(v,n, XMATCH(v, TAKE(keyId, n-1),, -1))), WRAPROWS(TOCOL(IFERROR(INDEX(data, row_nums, SEQUENCE(, r*c)), "")), c) )
Sample Results
Note: I unmerged columns B to F in my sample file, so the Factor data is now referencing range D6:F25 instead of G1:I25.
This method assumes each item always has the same number of records (5 rows each). If the number of records is not consistent, however, a "fill down" approach is needed:
=LET( FILLDOWN, LAMBDA(range, SCAN("", range, LAMBDA(a,v, IF(v="", a, v)))), keyId, FILLDOWN(A6:A25) & FILLDOWN(B6:B25) & FILLDOWN(C6:C25) & "|" & SCAN(0, A6:A25, LAMBDA(a,v, IF(v="", a+1, 1))), rowId, SEQUENCE(ROWS(keyId)), row_nums, MAP(keyId, rowId, LAMBDA(v,n, XMATCH(v, TAKE(keyId, n-1),, -1))), IFERROR(INDEX(D6:F25, row_nums, {1,2,3}), "") )
EDIT: you may need to remove the concatenation of column B (week number) from the keyID array. See the v2 file attached, if the first file does not work as expected...
- Excel_StrugglerCopper Contributor
Hi djclements,
First and foremost, thank you for your detailed response.
Your solution and mine both function correctly in terms of retrieval order. However, I believe the explanation could have been clearer.
I tested your solutions, primarily the fill-down approach, given the inconsistent number of records in my workbook.
Unfortunately, with a sufficient number of rows, I still encounter performance issues using your solution, similar to what I experienced with mine. I tested around 8,000 rows.I've attached a sample for you to test yourself.
Simply adding another column with data validation for the week is not a feasible solution for achieving the desired result in my workbook. My sample is highly simplified compared to my actual workbook, so it might give that impression. Assume a high number of rows in any case (about 8.000-15.000).I'd love to hear if you have any other ideas to address my issue. I'm still inclined towards splitting the data into sub-sheets for simplicity and performance stability, but I'm unsure if this is technically feasible in Excel.
Cheers- djclementsBronze Contributor
Excel_Struggler The performance issue in this case is due to an array object (keyId) being passed to the lookup_array argument of XMATCH. If we spill the keyId results directly to a separate range in the worksheet, then reference the spill range in the lookup_array, it will drastically improve the calculation speed.
In the attached revision, I've defined the FILLDOWN function in Name Manager, moved the keyId formula to cell I6, and simplified the final formula in cell F6. I tested it to 16,000 rows and the calculation lag was virtually unnoticeable on my system (milliseconds). Hopefully it will perform well enough that you can avoid splitting the data into multiple sheets.
Cheers!