AML & Fraud Analytics Path · Mission 10 of 30Easy

Wire vs cash — volume by channel group

CASE expression inside GROUP BY to bucket raw values into analytically-meaningful groups

Back to AML & Fraud Analytics

The Brief

Marcus WellerDirector of AML Operationsaml-ops

The board wants a one-liner on where the money flows. Roll the seven transaction channels into two buckets: 'cash' (any channel starting with `cash_`) and 'wire' (any channel starting with `wire_`). Ignore everything else — ACH, card, and online transfers go in a bucket we're not reporting today. Sum only positive (credit) amounts, exclude reversals. Return `channel_group` and `total_volume`, ordered by `total_volume DESC`. Two rows.

You'll practice

CASE aggregationRatios

Tables & columns available

aml_transactionsfact9 columns
ColumnTypeKey
txn_idINTPK
account_idINTFK → aml_accounts
posted_dateTEXT
posted_tsTEXT
amountREAL
channelTEXT
counterparty_nameTEXT
counterparty_account_idINT
is_reversalINT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Inside GROUP BY you can use a CASE expression, but the cleaner pattern is to compute the bucket in the SELECT list AND the GROUP BY, OR wrap in a subquery. The most readable form: put the CASE in the SELECT, alias it, then `GROUP BY 1` in dialects that support ordinal grouping.

Hint 2

`CASE WHEN channel LIKE 'cash_%' THEN 'cash' WHEN channel LIKE 'wire_%' THEN 'wire' ELSE NULL END` — and filter the NULLs out in WHERE using `channel LIKE 'cash_%' OR channel LIKE 'wire_%'`.

Hint 3

Don't forget `amount > 0 AND is_reversal = 0`. Withdrawals and reversals are negative (or flagged); they'll zero out your incoming volume if you include them.