Forum Discussion
JWorthers
Dec 08, 2023Copper Contributor
Need to speed up Spreadsheet
Hi All, I have a very large dataset in Sheet2. This dataset has a bunch of formula applied based on inputs on Sheet1. On Sheet1, I have some standalone calcs and also some inputs and graphical o...
Patrick2788
Dec 09, 2023Silver Contributor
Adding a macro to this large workbook is putting a bandage on a big problem and introducing a security element where it's not needed.
The way to best optimize this is to reduce the number of inputs. The workbook posted is slow because it has a ton of scalar-based based formulas (1 cell = 1 formula). This adds up quickly with 900,000 rows.
These are the formulas I've added.
The intervals column repeated:
=TOCOL(times*SEQUENCE(,37866,1,0),,1)
The KW column in sheet2. The '2' in the XLOOKUP is for binary search (ascending). Since your times are in ascending order, we can speed up the search a bit with a binary search.
=XLOOKUP(B5#,times,Sheet1!F9#,,,2)
The 'Higher/Lower' column:
=LET(
a, DROP(C5#, -1),
b, DROP(C5#, 1),
IF(a > b, "Higher", "Lower")
)
The final column - I call it 'status':
=LET(
counter, SEQUENCE(ROWS(D5#)),
MAP(
counter,
D5#,
LAMBDA(c, d,
LET(
status, IFERROR(TEXTJOIN("-", , CHOOSEROWS(D5#, c, c + 1)), ""),
SWITCH(
status,
"Higher-Higher", "Really High",
"Higher-Lower", "Higher",
"Lower-Lower", "Really Low",
"Lower-Higher", "Lower",
d
)
)
)
)
)
The workbook is now an XLSX - 20 MB.
- JWorthersDec 11, 2023Copper Contributor
Hi Patrick2788
Thanks for taking a look and giving examples! I just set up the 'Test Calc' as a simple workbook for testing macros, but actually your examples for modifying the formulas are really interesting. I've not really come across using formulas in this way before.
My main calc is mostly a mess of nested 'IF' functions. Is there an easy way of making these more efficient? or am I going to have to go through each formula one-by-one trying to rewrite for efficiency? I know AI can sometimes help in this area, but it's usually after a long battle getting the ruddy thing to understand the requirements.
Many thanks.
- Patrick2788Dec 11, 2023Silver ContributorThe way I approach writing logic in Excel: if there's more than 3 IFs - Am I better using a lookup function or SWITCH?
I'm away of IFS but prefer not to use.