In Appian, write an expression rule to find duplicate values from an integer array.
Input:
{1, 2, 3, 1, 4, 8, 9, 4, 3}Expected output:
{1, 3, 4}
In Appian, write an expression rule to find duplicate values from an integer array.
Input:
Expected output:
Answer
We can use a!forEach(), wherecontains(), count(), and union() to identify the duplicates element in Appain in a given array.
Appian code
Let’s break this down:
1. Input array
The values 1, 3, and 4 each appear twice, so the expected output is:
2. Loop through the array with a!forEach()
a!forEach() evaluates the expression once for each element of local!data. Inside the loop, fv!item is the current value: 1 on the first iteration, 2 on the second, and so on.
3. Find each value’s positions with wherecontains()
wherecontains() returns the positions where the current value appears in the array:
Current value | Positions returned | Count |
|---|---|---|
|
| 2 |
|
| 1 |
|
| 2 |
|
| 2 |
|
| 1 |
|
| 1 |
Appian list positions start at 1, so the first element is at position 1.
4. Test for a duplicate with count()
count() counts the positions wherecontains() returned. A count above 1 means the value appears more than once. A count of 1 means it appears only once.
5. Return the duplicates with if()
After the loop, local!duplicateItems contains {1, 3, 1, 4, 4, 3}. Duplicates are isolated, but each one still appears once per occurrence.
6. Remove the repeats with union()
union() combines two lists and returns their distinct values. Passing the same list twice is a common Appian technique for removing duplicates. Here it collapses the repeated 1, 3, and 4 and drops the empty lists, leaving:
Interview tip: be ready to explain the difference between finding duplicates and removing them. The count(wherecontains(...)) > 1 condition finds them, and union() removes the repeats from the result.
Output:

How to find unique values in an array in Appian:
Now let us remove the duplicate arrays in given array and only return non-duplicate values from the array
Sometimes you need the values that appear exactly once in an array and want to leave out anything repeated. This example uses a!forEach(), wherecontains(), count(), and if() to do that. It is the mirror image of the duplicates example, and it needs no union().
Appian code
Let’s break this down:
1. Input array
1, 3, and 4 each appear twice. 2, 8, and 9 appear once, so the expected output is:
2. Loop through the array with a!forEach()
a!forEach() evaluates the expression once for each element of local!data. Inside the loop, fv!item is the current value.
3. Find each value’s positions with wherecontains()
wherecontains() returns the positions where the current value appears in the array:
Current value | Positions returned | Count |
|---|---|---|
|
| 2 |
|
| 1 |
|
| 2 |
|
| 2 |
|
| 1 |
|
| 1 |
Appian list positions start at 1, so the first element is at position 1.
4. Test for a repeat with count()
A count above 1 means the value is repeated. A count of 1 means it appears only once, which is what we want to keep.
5. Keep the unique values with if()
This is the duplicates logic with the branches swapped. Repeated values return {}, and unique values return fv!item. a!forEach() drops empty lists from its result, so the loop returns just:
The values stay in their original order, and no extra step is needed.
Final Output:
A case to watch for
If the array has no unique values, every iteration returns {}. When the result is all empty lists, a!forEach() returns a list of empty lists instead of a clean empty list, so wrap the call in a!flatten() if that can happen: appian
Interview tip: know why this works. Returning {} makes a!forEach() skip the item, while returning null would keep a null in the output. That difference explains why this version needs no cleanup step.
For more Appian coding challenges visit : https://appianverse.com/coding
Try it yourself
Change the inputs or the expression and run it to see what it returns.
Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms