Qlik Community

Qlik Design Blog

All about product and Qlik solutions: scripting, data modeling, visual design, extensions, best practices, etc.

Employee
Employee

Repeat Function

The Repeat function can be used in both Qlik Sense and QlikView to repeat an input string a defined number of times.  It can be used in both the script and a chart expression.  This is how the Repeat function is defined in Qlik Sense Help:

 

Repeat() forms a string consisting of the input string repeated the number of times defined by the second argument.

 

Syntax:

 

Repeat(text[, repeat_count])

 

The function takes 2 arguments.  The first argument is the text that you would like to repeat.  This can be a single character or a combination of many characters.  It can be text defined in single quotes or a field name or variable.  The second argument is the repeat count which is the number of times the first argument should be repeated.  In the example measure below, the text to repeat is ‘My name is Jennell.’ along with chr(13) which represents a carriage return.  The second argument is 5 indicating that this input string should be repeated 5 times.

 

name.png

 

Here are the results in a Text & image object:

 

jennell.png

 

Simply enough, right?  In the example, the repeat count argument was set to 5 but I also could have used a variable or a numeric field to indicate the number of times the text should be repeated.  Let’s look at an example that uses Repeat in the script using field names.  In the script below, I am loading an inline table with a Letter field and a Number field.  In the Example table that I load, I am using the Repeat function to create the RepeatExample field which will repeat the string in the Letter field the number of times specified in the Number field.

 

script.png

 

Here is a preview of the Example table once the script is executed:

 

table.png

 

By using the fields, Letter and Number, for the arguments, the Repeat function is dynamic based on the data being loaded.  The Repeat function is a basic, easy-to-use function that can manipulate your data.  I am sure there are many other ways this function can be used.  Feel free to share how you use the Repeat function.

 

Thanks,

Jennell

2 Comments
sandeeps_hyd
New Contributor II

@Jennell_McIntire wrote:

The Repeat function can be used in both Qlik Sense and QlikView to repeat an input string a defined number of times.  It can be used in both the script and a chart expression.  This is how the Repeat function is defined in Qlik Sense Help:

 

Repeat() forms a string consisting of the input string repeated the number of times defined by the second argument.

 

Syntax:

 

Repeat(text[, repeat_count])

 

The function takes 2 arguments.  The first argument is the text that you would like to repeat.  This can be a single character or a combination of many characters.  It can be text defined in single quotes or a field name or variable.  The second argument is the repeat count which is the number of times the first argument should be repeated.  In the example measure below, the text to repeat is ‘My name is Jennell.’ along with chr(13) which represents a carriage return.  The second argument is 5 indicating that this input string should be repeated 5 times.

 

name.png

 

Here are the results in a Text & image object:

 

jennell.png

 

Simply enough, right?  In the example, the repeat count argument was set to 5 but I also could have used a variable or a numeric field to indicate the number of times the text should be repeated.  Let’s look at an example that uses Repeat in the script using field names.  In the script below, I am loading an inline table with a Letter field and a Number field.  In the Example table that I load, I am using the Repeat function to create the RepeatExample field which will repeat the string in the Letter field the number of times specified in the Number field.

 

script.png

 

Here is a preview of the Example table once the script is executed:

 

table.png

 

By using the fields, Letter and Number, for the arguments, the Repeat function is dynamic based on the data being loaded.  The Repeat function is a basic, easy-to-use function that can manipulate your data.  I am sure there are many other ways this function can be used.  Feel free to share how you use the Repeat function.

 

Thanks,

Jennell


Hi Jennel,

Is it possible to get decimal / precision repetitions  like in the below example?

Ex:

Repeat( ' * ', rating )  (Say rating = 4.5)

Thanks.

0 Likes
343 Views
sandeeps_hyd
New Contributor II

Also, please let me know if there exists any other function?

0 Likes
343 Views