# Data Analysis

<details>

<summary><strong>Top expense categories for a quarter</strong> (read)</summary>

To see where spend concentrated last quarter, pull transactions and group negative amounts by category.

**The Script**

```bash
#!/bin/bash
# top-expense-categories.sh

WORKSPACE_ID="<workspace-id>"
SINCE="2026-01-01"
UNTIL="2026-03-31"

echo "Top expense categories: $SINCE to $UNTIL"
echo ""

kick --workspace "$WORKSPACE_ID" transactions find \
  --since "$SINCE" \
  --until "$UNTIL" \
  --fields amount,category \
  --output json | \
jq -r '
  [.[] | select(.amount < 0)] |
  group_by(.category) |
  map({
    category: (.[0].category // "Uncategorized"),
    total: (map(.amount) | add),
    count: length
  }) |
  sort_by(.total) |
  .[] |
  "\(.category): $\(.total | fabs) (\(.count) transactions)"
'
```

**How to Customize**

* Filter to one entity's activity in Kick before exporting, or narrow dates per client
* Group by counterparty instead: `group_by(.counterparty)`
* Add a percentage of total with an extra `jq` pass

**What It Outputs**

```
Cloud Infrastructure: $12500.00 (36 transactions)
Payroll: $75000.00 (3 transactions)
```

</details>

<details>

<summary><strong>Cash flow statement by month</strong> (read)</summary>

To analyze operating, investing, and financing totals by month, use the cash flow statement report instead of rolling up raw transactions.

**The Script**

```bash
#!/bin/bash
# cash-flow-by-month.sh

WORKSPACE_ID="<workspace-id>"
ENTITY_ID=123
START_DATE="2026-01-01"
END_DATE="2026-03-31"

ledger_id=$(kick --workspace "$WORKSPACE_ID" accounting ledgers get --entity-id "$ENTITY_ID" --output json | jq -r '.ledgers[0].id')

kick --workspace "$WORKSPACE_ID" reports cash-flow-statement \
  --entity "$ENTITY_ID" \
  --ledger-id "$ledger_id" \
  --start-date "$START_DATE" \
  --end-date "$END_DATE" \
  --cycle month \
  --output json | jq .
```

**How to Customize**

* Add `--comparison previous_year` for year-over-year context
* Export vendor-level detail with `kick reports expenses-by-vendor` for the same entity and dates

**What It Outputs**

* JSON cash flow statement with monthly columns for the entity and period

</details>
