# 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.

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. |
| distinct | If the word distinct<br>occurs before the expression, all duplicates are disregarded. |

Examples and results:

Add the example script to your app and run it. To see the result, add the fields listed in the results column to a sheet in your app.

Examples and results

| Example | Result | Results once added to a sheet |
| --- | --- | --- |
| `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 dimension Amount:<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 |