Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
|
Nou pe simpatie: CriStiNutZa.. pe Simpatie
 | Femeie 24 ani Bucuresti cauta Barbat 26 - 80 ani |
|
|
Mrrrr's Forum (VIEW ONLY)InregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
|
| pus acum 13 ore#1 |
TRaPModerator
Postari: 977
|
|
I recently discovered the use of lastrow in formulas to make spills for specific ranges that update with the base range update and don't overlap. For example, I am summarizing some data from Pivot tables. I know, why not just do another Pivot table, or go with a complex PIVOTBY. I'm just trying to do some top 3 supplier formulas by categories and sums of quantities by top 3 suppliers and whatnot that I can easily copy/paste to multiple different files that already have the base Pivot table in them.
Regardless of my usage, here's how you can define a lastrow variable in LET and how you can use it to define a range:
=LET( lastrow; XMATCH("Grand Total"; A:A); range; C8:INDEX(C:C; lastrow); ) |
This will expand with the expansion of the Pivot table so I don't have to add finite ranges, nor do I have to go with much larger to account for possible Pivot table expansion. It works well since Grand Total appears only once and as soon as XMATCH finds it, it stops searching further.
In a Pivot let's say in column B you have 4 categories and want the spill next to the Pivot table to go by category. You set labels for categories to appear once in the pivot table column, then make firstrow and lastrow, and in the end you can stack the results - this way your spill will update with the pivot table for all categories involved; something like:
=LET( fRW_1; XMATCH("Category 1 name"; A:A); lRW_1; XMATCH("Category 2 name"; A:A) - 1; fRW_2; XMATCH("Category 2 name"; A:A); lRW_2; XMATCH("Category 3 name"; A:A) - 1; etc. rng_1; INDEX(C:C; fRW_1):INDEX(C:C; lRW_1); rng_2; INDEX(C:C; fRW_2):INDEX(C:C; lRW_2); etc. do some formulas with those ranges under some other variables, eg. result_1, result_2 etc. VSTACK(result_1; result_2; ...) ) |
If a fifth category appears you can set in the formula what to show: "NEW CATEGORY, PLEASE CHECK" - then you can update the formula with a new fRW, lRW and rng.
But what if no Pivot table and just want the last row regardless of cell content?
=LET( lastrow; XMATCH(TRUE; A:A; 0; -1); range; C8:INDEX(C:C; lastrow); ) |
The above searches the whole A:A column bottom to top so it's pretty consuming in terms of sheet recalculation (over 1 million cells). If you have one formula in the file, it's OK, if you have multiple, it's best to define a larger initial range instead. If your range is around 3000 rows increasing up to 7000, you can go with 10000 or 15000 rows:
=LET( lastrow; XMATCH(TRUE; A1:A15000; 0; -1); range; C8:INDEX(C:C; lastrow); ) |
How is it different from simply filtering the range instead? Well, in FILTER you must include a condition for it to FILTER OUT the blank cells and if your range has to have blank cells then you must add conditions based on other columns - I feel that with lastrow things are a little simpler.
One application I found for the above was the following filter spill - my database sheet currently has ~150 rows and expansion is slow, but I accounted for 1000. The difference in sheet recalculation vs using A:A was ~73% faster with using A1:A1000.
=LET( lastrow; XMATCH(TRUE; database!A1:A1000<>""; 0; -1); filter_rng; SE16N!A2:INDEX(database!I:I; lastrow); search_rng; SE16N!J2:INDEX(database!J:J; lastrow); FILTER(filter_rng; ISNUMBER(SEARCH("*" & IFERROR(SUBSTITUTE(B2;" ";"*");B2) & "*"; search_rng; 1)); "n/a") ) |
|
|
| |
|