unique
Returns a list of unique values (removes duplicates).
The first parameter takes a list, column, or row.
The optional second parameter allows you to apply an amending function — also known as a helper function — to each data value before the comparison. You must write the helper function as a lambda expression.
Parameters
LIST (list, column, or row)
The input list. This can be a list or list-like object (column or row).
HELPER FUNCTION (function)
Optional. The function to apply to each value before the comparison.
You must write the helper function as a lambda expression — see the examples below.
Examples
The first parameter can take a list.
ATL in Script | Resulting List | Printed Result |
---|---|---|
[[ myList = (4, 5, 6, 4, 5, 2) unique(myList) ]] | (4, 5, 6, 2) | 4, 5, 6 and 2 |
To amend each input value before the comparison, use the optional second parameter.
ATL in Script | Resulting List | Printed Result |
---|---|---|
[[ myList = (4, 5, 5.2, 5.7) unique(myList, x -> truncate(x)) ]] | (4, 5) | 4 and 5 |
The lambda expression x -> truncate(x)
truncates each value to its integer part. 5.2 truncates to 5. There is already a 5 in the list, so the original value (5.2) does not appear in the output. The same applies to 5.7.
ATL in Script | Resulting List | Printed Result |
---|---|---|
[[ myList = (4, 5, 5.2, 5.7) unique(myList, value -> round(value, 0)) ]] | (4, 5, 5.7) | 4, 5 and 5.7 |
The lambda expression value -> round(value, 0)
rounds each value to zero decimal places. 5.2 rounds down to 5; and since there is already a 5 in the list, the original value (5.2) does not appear in the output. 5.7 rounds up to 6; and since there isn't a 6 already in the list, the original value (5.7) does appear in the output.
Note
See ATL Guide > Lambda expressions for further guidance.
Using unique with table data
Assume a "Describe the Table" project with this data:
ID | Region | Branch | Sales | |
---|---|---|---|---|
Row 1 | 1001 | South | Atlanta | 357,000 |
Row 2 | 1002 | Northeast | Boston | 294,000 |
Row 3 | 1003 | south | Dallas | 324,000 |
Row 4 | 1004 | SOUTH | Houston | 316,000 |
Row 5 | 1005 | Northeast | New York | 471,000 |
The first parameter can take a column variable.
ATL in Script | Printed Result |
---|---|
| South, Northeast, south and SOUTH |
| South and Northeast |
The lambda expression x -> joinStrings(upper(x[0:1]), lower(x[1: ]))
amends each Region value so the first character is uppercase and all subsequent characters are lowercase.
Note
In a "Describe Row in Context" project, the column variable is RegionColumn
.