Dynamic Transaction Risk Analyzer
Medium
You are given a list of customer transactions. Each transaction contains:
- customer
- amount
- type — "CREDIT" or "DEBIT"
- status — "SUCCESS" or "FAILED"
Your task is to build an Appian expression that:
- Ignores all failed transactions.
- For each customer, calculate their net transaction amount:
- CREDIT → add the amount
- DEBIT → subtract the amount
- Assign a risk level:
- HIGH → net amount < -5000
- MEDIUM → net amount between -5000 and 0
- LOW → net amount > 0
- Return only customers with HIGH or MEDIUM risk.
- Sort the result by:
- HIGH risk first
- MEDIUM risk second
- Within the same risk level, lowest net amount first.
- Return the final result in this format:
{
{customer: "John", netAmount: -7200, risk: "HIGH"},
{customer: "David", netAmount: -2500, risk: "MEDIUM"}
}
ri! Rule Inputs
ri!transactionsList of Map{
{customer: "John", amount: 4000, type: "CREDIT", status: "SUCCESS"},
{customer: "John", amount: 12000, type: "DEBIT", status: "SUCCESS"},
{customer: "John", amount: 3000, type: "CREDIT", status: "FAILED"},
{customer: "David", amount: 2000, type: "CREDIT", status: "SUCCESS"},
{customer: "David", amount: 4500, type: "DEBIT", status: "SUCCESS"},
{customer: "Sarah", amount: 10000, type: "CREDIT", status: "SUCCESS"},
{customer: "Sarah", amount: 2000, type: "DEBIT", status: "SUCCESS"},
{customer: "Mike", amount: 1000, type: "CREDIT", status: "FAILED"},
{customer: "Mike", amount: 6000, type: "DEBIT", status: "SUCCESS"}
}Example 1 — Case 1
Input: ri!transactions
{
{customer: "John", amount: 4000, type: "CREDIT", status: "SUCCESS"},
{customer: "John", amount: 12000, type: "DEBIT", status: "SUCCESS"},
{customer: "John", amount: 3000, type: "CREDIT", status: "FAILED"},
{customer: "David", amount: 2000, type: "CREDIT", status: "SUCCESS"},
{customer: "David", amount: 4500, type: "DEBIT", status: "SUCCESS"},
{customer: "Sarah", amount: 10000, type: "CREDIT", status: "SUCCESS"},
{customer: "Sarah", amount: 2000, type: "DEBIT", status: "SUCCESS"},
{customer: "Mike", amount: 1000, type: "CREDIT", status: "FAILED"},
{customer: "Mike", amount: 6000, type: "DEBIT", status: "SUCCESS"},
{customer: "Mike", amount: 10000, type: "DEBIT", status: "SUCCESS"}
}Output:
{
a!map(customer: "Mike", netAmount: -16000.0, risk: "HIGH"),
a!map(customer: "John", netAmount: -8000.0, risk: "HIGH"),
a!map(customer: "David", netAmount: -2500.0, risk: "MEDIUM")
}Example 2 — Case 2
Input: ri!transactions
{
{customer: "Alice", amount: 5000, type: "CREDIT", status: "SUCCESS"},
{customer: "Alice", amount: 10000, type: "DEBIT", status: "SUCCESS"},
{customer: "Bob", amount: 5000, type: "CREDIT", status: "SUCCESS"},
{customer: "Bob", amount: 5000, type: "DEBIT", status: "SUCCESS"},
{customer: "Charlie", amount: 8000, type: "CREDIT", status: "SUCCESS"}
}Output:
{
a!map(customer: "Alice", netAmount: -5000.0, risk: "MEDIUM"),
a!map(customer: "Bob", netAmount: 0.0, risk: "MEDIUM")
}Example 3 — Case 3
Input: ri!transactions
{
{customer: "Alex", amount: 10000, type: "DEBIT", status: "FAILED"},
{customer: "Alex", amount: 3000, type: "CREDIT", status: "FAILED"},
{customer: "Brian", amount: 2000, type: "CREDIT", status: "SUCCESS"},
{customer: "Brian", amount: 9000, type: "DEBIT", status: "SUCCESS"},
{customer: "Chris", amount: 15000, type: "DEBIT", status: "SUCCESS"},
{customer: "Chris", amount: 5000, type: "CREDIT", status: "FAILED"}
}Output:
{
a!map(customer: "Chris", netAmount: -15000.0, risk: "HIGH"),
a!map(customer: "Brian", netAmount: -7000.0, risk: "HIGH")
}Appian Expression Tips
- • Use
ri!variableNamefor rule inputs - • Use
a!localVariables(local!x: …, body)for locals - • Use
a!forEach(items: …, expression: fv!item)to iterate - • Use
where()/reject(fn!isnull, list)to filter