# Concat - script function

Concat() is used to combine string values. The script function returns the aggregated string concatenation of all values of the expression iterated over a number of records as defined by a group by clause.

Syntax:

Concat (Concat ([ distinct ] string [, delimiter [, sort\_weight]][ distinct ] string [, delimiter [, sort\_weight]]))

Return data type: string

Arguments:

The expression or field containing the string to be processed.

Concat arguments

| Argument | Description |
| --- | --- |
| string | The expression or field containing the string to be processed. |
| delimiter | Each value may be separated by the string found in delimiter. |
| sort\_weight | The order of concatenation may be determined by the value of the dimension sort\_weight, if present, with the string corresponding to the lowest value appearing first in the concatenation. When 0 is used as the sort\_weight argument value, sorting is not applied to the output. If the sort\_weight argument is omitted, the function defaults to alphanumeric sorting. |
| distinct | If the word distinct<br>occurs before the expression, all duplicates are disregarded. |

Examples and results:

Add the example script to your document and run it. Then add, at least, the fields listed in the results column to a sheet in your document to see the result.

Examples and results

| Example | Result field | Result value |
| --- | --- | --- |
| `TeamData:<br>`<br>`LOAD * inline [`<br>`SalesGroup\|Team\|Date\|Amount<br>`<br>`East\|Gamma\|01/05/2013\|20000<br>`<br>`East\|Gamma\|02/05/2013\|20000<br>`<br>`West\|Zeta\|01/06/2013\|19000<br>`<br>`East\|Alpha\|01/07/2013\|25000<br>`<br>`East\|Delta\|01/08/2013\|14000<br>`<br>`West\|Epsilon\|01/09/2013\|17000<br>`<br>`West\|Eta\|01/10/2013\|14000<br>`<br>`East\|Beta\|01/11/2013\|20000<br>`<br>`West\|Theta\|01/12/2013\|23000<br>`<br>`] (delimiter is '\|');`<br>` `<br>`Concat1:`<br>`LOAD SalesGroup,Concat(Team) as TeamConcat1  Resident TeamData Group By SalesGroup;` | SalesGroup<br><br>East<br><br>West | TeamConcat1<br><br>AlphaBetaDeltaGammaGamma<br><br>EpsilonEtaThetaZeta |
| Given that the TeamData table is loaded as in the previous example:<br><br>`LOAD SalesGroup,Concat(distinct Team,'-') as TeamConcat2  Resident TeamData Group By SalesGroup;` | SalesGroup<br><br>East<br><br>West | TeamConcat2<br><br>Alpha-Beta-Delta-Gamma<br><br>Epsilon-Eta-Theta-Zeta |
| Given that the TeamData table is loaded as in the previous example. Because the argument for sort\_weight is added, the results are ordered by the value of the dimensionAmount:<br><br>`LOAD SalesGroup,Concat(distinct Team,'-',Amount) as TeamConcat2  Resident TeamData Group By SalesGroup;` | SalesGroup<br><br>East<br><br>West | TeamConcat2<br><br>Delta-Beta-Gamma-Alpha<br><br>Eta-Epsilon-Zeta-Theta |
| ```<br>T1:<br>Load *<br>INLINE [<br>EmployeeID, Unit, Department, Age, Salary, Country<br>1, A, z, 30, 81000, GER<br>2, B, z, 29, 39000, IRL<br>3, B, y, 40, 58000, IRL<br>4, A, y, 45, 71000, USA<br>5, A, z, 26, 79000, GBR<br>6, B, z, 20, 31000, GER<br>7, A, y, 56, 29000, USA<br>8, A, y, 35, 52000, GBR<br>];<br><br>T2:<br>Load<br>Unit,<br>Concat(Age, '-', 0) as ConcatNoSort<br>resident T1 group by Unit;<br>``` | Unit<br><br>A<br><br>B | ConcatNoSort<br><br>30-45-26-56-35<br><br>29-40-20 |