Table Manipulation
group-by
Group a table of transactions by a key function. This is one of the most powerful functions for analysis.
Syntax:
(group-by table key-fn)
Parameters:
table: The list of transactionskey-fn: A lambda function that extracts the grouping key from each transaction
Returns: A list of groups, where each group is:
("GroupName" (transaction1) (transaction2) ...)
Examples:
Group by Category
kakei transform --program "(group-by table (lambda (pair) (cdr (assoc 'category (cdr pair)))))"
Output structure:
(("Food"
(ID-001 . ((date . "2025-01-01") (amount . -1000) ...)))
("Transport"
(ID-002 . ((date . "2025-01-02") (amount . -2000) ...)))
("Salary"
(ID-003 . ((date . "2025-01-15") (amount . 50000) ...))))
Group by Account
kakei transform --program "(group-by table (lambda (pair) (cdr (assoc 'account (cdr pair)))))"
Group by Date
kakei transform --program "(group-by table (lambda (pair) (cdr (assoc 'date (cdr pair)))))"
How it Works:
For each transaction in the table:
- The lambda function extracts a grouping key (e.g., category name)
- Transactions with the same key are grouped together
- The result is a list of groups labeled by their key