Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
swarup_malli
Specialist
Specialist

Could anyone explain how concat function works in the following code?


Hello,

I was trying to understand the concat function any explanation would be very helpful.I know it concatenates all the contents of the field.I want to know what its doing in the code I have written below.

In the code below the contents of the field TEXT_NOTE are being concatenated  with the contents of NOTE_SEQ( which is another filed btw )  NOTE_SEQ is being used for sorting/grouping here.

 

NoConcatenate

LOAD
WARRANTY_CLAIM,
Concat(TEXT_NOTE, ' ',NOTE_SEQ) as TEXT_NOTE,
Concat(NOTE_SEQ,', ',NOTE_SEQ) as NOTE_SEQ
Resident Second
Group By WARRANTY_CLAIM;
DROP Table Second;

This is the result I get in the front end

qvCommunity.png

SM

1 Solution

Accepted Solutions
swuehl
MVP
MVP

LOAD

     CONCAT(TEXT) as ConcatenatedText

INLINE [

TEXT

This

Text

Will

Be

Concatenated

];

Or from the Help:

Examples of Concat Functions

The CONCAT() function should not be confused with the CONCATENATE script keyword.

In its simplest form, Concat() is used to string / join together values/words/selections into one string. However, it can be utilized in a number of ways to help you solve different problems. All the examples are based upon the following table:

Simple String Concatenation

As mentioned earlier, the concat function lets you string together a list of values. These values can be hard coded or driven by 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, the date column is added to sort the values.

=CONCAT(MyColumn, ',', Date)

Result: JKL,VWX,GHI,ABC,STU,PQR,MNO,DEF

Concat() within an Expression/Set Statement

Passing multiple dynamic values to a set analysis expression

There are occasions when you want to pass a dynamic selection of values to a set statement. To do this you 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, use the Chr() function:

=CONCAT(Chr(39)&MyColumn&Chr(39),',')

You can then pass this concat statement to the inside of an expression:

=Sum({<MyColumn={$(=CONCAT(Chr(39)&MyColumn&Chr(39),','))}>} Value)

In most instances, this technique would be used where data islands are present. It lets you 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.

Concat() in the Script

Concat can also be used in the script to convert multiple rows into one single column value, just as any other aggregation.

Remembering the source data used earlier, the result of script side CONCAT is as follows:

The following is the result of this script function:

Using Rank() to influence the Concat()

When you start to utilize other function in conjunction with concat() you can start to achieve clever results. In this example, Rank() has been used to grab the top three performers (based on Value) and string them together.

=CONCAT(IF(aggr(Rank(sum(Value)),MyColumn)<=3,MyColumn),',') 

Result: ABC,MNO,STU

View solution in original post

2 Replies
maxgro
MVP
MVP

You find some useful examples in the online Qlik help, I just copied it below

Examples of Concat Functions

The CONCAT() function should not be confused with the CONCATENATE script keyword.

In its simplest form, Concat() is used to string / join together values/words/selections into one string. However, it can be utilized in a number of ways to help you solve different problems. All the examples are based upon the following table:

Simple String Concatenation

As mentioned earlier, the concat function lets you string together a list of values. These values can be hard coded or driven by 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, the date column is added to sort the values.

=CONCAT(MyColumn, ',', Date)

Result: JKL,VWX,GHI,ABC,STU,PQR,MNO,DEF

Concat() within an Expression/Set Statement

Passing multiple dynamic values to a set analysis expression

There are occasions when you want to pass a dynamic selection of values to a set statement. To do this you 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, use the Chr() function:

=CONCAT(Chr(39)&MyColumn&Chr(39),',')

You can then pass this concat statement to the inside of an expression:

=Sum({<MyColumn={$(=CONCAT(Chr(39)&MyColumn&Chr(39),','))}>} Value)

In most instances, this technique would be used where data islands are present. It lets you 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.

Concat() in the Script

Concat can also be used in the script to convert multiple rows into one single column value, just as any other aggregation.

Remembering the source data used earlier, the result of script side CONCAT is as follows:

The following is the result of this script function:

Using Rank() to influence the Concat()

When you start to utilize other function in conjunction with concat() you can start to achieve clever results. In this example, Rank() has been used to grab the top three performers (based on Value) and string them together.

=CONCAT(IF(aggr(Rank(sum(Value)),MyColumn)<=3,MyColumn),',') 

Result: ABC,MNO,STU

swuehl
MVP
MVP

LOAD

     CONCAT(TEXT) as ConcatenatedText

INLINE [

TEXT

This

Text

Will

Be

Concatenated

];

Or from the Help:

Examples of Concat Functions

The CONCAT() function should not be confused with the CONCATENATE script keyword.

In its simplest form, Concat() is used to string / join together values/words/selections into one string. However, it can be utilized in a number of ways to help you solve different problems. All the examples are based upon the following table:

Simple String Concatenation

As mentioned earlier, the concat function lets you string together a list of values. These values can be hard coded or driven by 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, the date column is added to sort the values.

=CONCAT(MyColumn, ',', Date)

Result: JKL,VWX,GHI,ABC,STU,PQR,MNO,DEF

Concat() within an Expression/Set Statement

Passing multiple dynamic values to a set analysis expression

There are occasions when you want to pass a dynamic selection of values to a set statement. To do this you 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, use the Chr() function:

=CONCAT(Chr(39)&MyColumn&Chr(39),',')

You can then pass this concat statement to the inside of an expression:

=Sum({<MyColumn={$(=CONCAT(Chr(39)&MyColumn&Chr(39),','))}>} Value)

In most instances, this technique would be used where data islands are present. It lets you 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.

Concat() in the Script

Concat can also be used in the script to convert multiple rows into one single column value, just as any other aggregation.

Remembering the source data used earlier, the result of script side CONCAT is as follows:

The following is the result of this script function:

Using Rank() to influence the Concat()

When you start to utilize other function in conjunction with concat() you can start to achieve clever results. In this example, Rank() has been used to grab the top three performers (based on Value) and string them together.

=CONCAT(IF(aggr(Rank(sum(Value)),MyColumn)<=3,MyColumn),',') 

Result: ABC,MNO,STU