Qlik Sense Concat
Qlik Sense Concat
INTRODUCTION ................................................................................................................. 3
SUMMARY .......................................................................................................................... 5
EXAMPLE
concat( Code, ';' )
concat( FirstName&' '&LastName, ',' )
concat( distinct Code, ';' )
concat( total Name, ';' , Date )
concat( total <Grp> Name, ';' , Date)
As mentioned earlier, the function lets you string together a list of values. These values can
be hard coded or driven my selections/data.
=CONCAT(MyColumn,',')
=CONCAT(DISTINCT MyColumn,',')
This simple concat statement would string together all of the possible values from the column
MyColumn. You may wish to add the DISTINCT keyword. This would ensure that each value
is only displayed once in the string.
ABC,DEF,GHI,JKL,MNO,PQR,STU,VWX
When using a simple concat, you have the option to add a sort weight to the function to order
the string values by a column of your choice. In the example below, I have added the date
column to sort the values…..
Result: JKL,VWX,GHI,ABC,STU,PQR,MNO,DEF
There are occasions when you want to pass a dynamic selection of values to a set
statement. To do this I would need to add some single quotes to the string so that the
CONCAT() function returns e.g. 'JKL','VWX'. But you cannot have the single quotes as they
are, since they then would be interpreted when the Concat is evaluated instead of when the
set expression is evaluated. Instead I use the Chr() function:
=CONCAT(Chr(39)&MyColumn&Chr(39),',')
=Sum({<MyColumn={$(=CONCAT(Chr(39)&MyColumn&Chr(39),','))}>} Value)
In most instances, this technique would be used where data islands are present. It lets me
pass values to an expression that will not affect any part of the data model as the data island
table is not joined to it.
Remembering the source data we have earlier. The result of script side CONCAT can be
seen below...
=CONCAT(IF(aggr(Rank(sum(Value)),MyColumn)<=3,MyColumn),',')
Result: ABC,MNO,STU
Summary
As you can see, the Concat function is a neat and powerful tool that can be used throughout
your QlikView applications. It can be used to manipulate tables in the script and drive Set
Analysis statements.