## TL;DR

A Stripe Sigma query joining failed invoices to their charges and grouping by decline code shows exactly why invoices are failing: insufficient_funds vs do_not_honor vs expired_card each need a different recovery play. Write the query against the invoices and charges tables, filter to failed payment attempts in your window, group by the charge's failure code, and order by count. Refresh it on a schedule and hand it to the dunning owner. This turns 'payments are failing' into a prioritized fix list.

## The query

```text
Stripe Sigma query: failed invoices grouped by decline code
```

## Use this when

- Payment ops dashboard for invoice failure reasons
- Prioritizing dunning work by decline code
- Writing Sigma queries on Stripe billing data

## Not for

- Real-time failed-payment alerts (use webhooks)
- Non-Stripe payment data (Sigma only sees Stripe)

## Steps

1. Identify the tables: invoices for the billing record, charges for the failure code.
   Expected output: You know the join path before writing SQL.
2. Filter to the window and to invoices with failed payment attempts.
   Expected output: The dataset is scoped to real failures.
3. Group by the charge failure code and count, ordered descending.
   Expected output: The top decline reasons surface first.
4. Save the query and schedule it for the dunning owner.
   Expected output: The report lands without manual runs.
5. Map each top code to its recovery play (retry, new card, customer contact).
   Expected output: The dashboard drives action, not just awareness.

## Variant phrasings

### Stripe Sigma failed invoices by decline code

### Sigma query invoice payment failures

### group Stripe charges by failure code Sigma

## Root cause

Sigma can answer this because Stripe stores the full payment attempt history with structured decline codes; grouping by code separates recoverable failures (insufficient_funds, try again later) from terminal ones (stolen_card, get a new card). Without the grouping, dunning treats every failure the same and wastes retries.

## Edge cases

- Sigma data lags real time by hours; do not use it for alerting
- Some failures never produce a charge (no payment method); count those separately from the invoice side

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_SL5r-hRxrP7MNkcfCO9Z5A
