Adding Window Functions to a Spreadsheet getgrist.com · 23 points · 14 comments ...

@best

Adding Window Functions to a Spreadsheet getgrist.com · 23 points · 14 comments · HN thread

TL;DR Grist, a spreadsheet with database foundations, presents its PREVIOUS(), NEXT(), RANK() and ordered lookup functions as a fix for row-relative formulas that break when rows are inserted, deleted or sorted. The post shows running balances, per-group totals and nearest-match lookups such as pay rates and commission tiers, and claims PREVIOUS() handled 20,000 rows in seconds while a scanning version did not finish in five minutes.

  • In traditional spreadsheets, a running balance refers to the cell above, so inserting a row silently skips a transaction and deleting one produces #REF! errors.
  • Grist's PREVIOUS(rec, order_by="Date") returns the previous record by date, so the order lives in the formula rather than the view and balances stay correct after inserts, deletes and sorts.
  • The group_by argument computes separate running balances per card member in one table, avoiding a table per person.
  • lookupRecords(...).find.le(value) performs a nearest-match lookup on sorted records, covering pay rates by date, commission tiers, shipping weights and tax brackets.
  • The author reports that on 20,000 transactions PREVIOUS() finished in seconds while a scanning formula ran for over five minutes, because ordered lookups use binary search.
  • Excel's approximate VLOOKUP gives unexpected results when its first column is unsorted, whereas Grist sorts by the order given in the formula.

Discussion The thread is small and split between interest in spreadsheets with code-friendly formulas and skepticism about Grist's syntax. Commenters mostly question the readability of the Python-style formulas, the mix of capitalised spreadsheet function names with Python, and whether the approach is needlessly verbose. A few note that the spreadsheet world is drifting toward database-style behaviour, and one commenter shares their own alternative spreadsheet project. The mood is curious and mildly critical rather than hostile.

  • Syntax is awkward and hard to read (many): Several commenters find the mix of SHOUTING function names, dot access on returned records and $-prefixed fields strange, and ask whether it conveys intent clearly or needs memorising.
  • Spreadsheets becoming database-like is reasonable but hard (some): Some see the move toward DB-style behaviour as a sensible direction, but argue that decades of spreadsheet syntax make it difficult to add without making simple tasks complicated.
  • Returning a table with index lookup would be cleaner (a few): One commenter suggests returning a table and using an index lookup, as Google Sheets does for finance data, instead of dot access on a record.
  • Teach SQL and spreadsheets' logic more widely (a few): A commenter jokes about teaching SQL in primary school, and another expects LLMs to reduce the need for such languages to a specialist skill.
  • Reinvention of older business tools (a few): One commenter feels the industry keeps reinventing BusinessObjects-style reporting tools.
  • Alternative spreadsheet projects with code-based formulas (a few): Commenters mention omasheet (a Rust and Polars spreadsheet with its own DSL) and pyspread as other approaches to code-friendly spreadsheets.

Links from the comments

#spreadsheets #Grist #formulas #databases #Python