Forum Discussion
Excessive time preforming calculations
- May 19, 2021
Detlef is right, such projects better to do with data model using Power Pivot and Power Query. But that will require to rebuild everything practically from scratch.
With current workbook I'd at least to convert ranges to structured tables. That itself allows to optimize formulas and improve performance. Another variant is dynamic ranges, but that's harder in maintenance.
Some formulas could be optimized independently of above. For example, instead of calculating max of the range, keep reference on sequential numbers range and use MAXIFS to find position of max, it could be used something like =XMATCH(bigNumber, range, -1).
As for filtered rows, you may add helper column to first table as
=AGGREGATE(3,5,[@STOCK])and in next table use helper columns as
=XLOOKUP([@STOCK],tblStratCalcsNYSE[STOCK],tblStratCalcsNYSE[Helper])
Another way is to add helper column in 'StratCalcs-NYSE' sheet with formula as
=AGGREGATE(3,5,A5)
It returns 1 for visible row and 0 for hidden one. Let say it'll be in column H, when
=SUMPRODUCT(--('StratCalcs-NYSE'!A$5:A$905='File Review-NYSE'!A5)*'StratCalcs-NYSE'!H$5:H$905)- mwwoodruMay 19, 2021Copper ContributorSergei - thank you for this suggestion. I have tried =AGGREGATE(3,5,A5). But still does not seem to do what I need. The stocks listed on sheet StratCalcs are to be Filtered (not hidden) to show only the ones that meet certain criteria. What I want to do is in sheet File Review (which shows all of the trades of all of the stocks) to be able to display (by filtering) only the trades of stocks displayed on sheet StratCalcs when that sheet has been filtered. was able to add the helper column/AGGREGATE function to sheet StratCalcs, but does't seem to make it any easier to do what I want (i.e. perform a COUNTIF on a Filtered list). The above complicated SUMPRODUCT function does, but is not good when done over 100,000+ trades. Do you have any other way I can do a COUNTIF function on a Filtered (not hidden) list? Thanks - Michael
- SergeiBaklanMay 19, 2021Diamond Contributor
AGGREGATE works the same way for filtered and manually hided rows. It returns 1 if row is visible and 0 if not visible.
I don't know other ways. Or with OFFSET() as in your initial formula or with helper column and AGGREGATE / SUBTOTAL (it works the same way). But OFFSET is volatile function which recalculates with any other cell recalculation which could reduce the performance dramatically.
As for COUNTIFS vs SUMPRODUCT it depends on which Excel you are. Microsoft improved performance significantly during previous 2-3 years. I don't think above functions have big difference in performance for the latest versions of Excel.
- mwwoodruMay 19, 2021Copper ContributorI agree. Although, I need to have the Helper column (with 1 or 0) placed in the File Review sheet (where all trades are listed) so that I can then filter this table to display only trades with a 1. Problem I am having is that I do not know how to get the AGGREGATE function to work, because there is a many to one relationship. Meaning, sheet File Review has many rows of trades from the same stock which is listed only once in sheet StratCalcs (the sheet that will be filtered prior to filtering the File Review sheet). Not sure if this helps to explain things. If not, I can attach a step by step graphic to show what I am doing.