Loop And Reduce: what is it and how can be used on Qlik Saas?

Sometimes, while developing QlikSense applications, you need to guarantee the “data segregation“, what is it?

With data segregation, users will be able to see only data which are related to them and they won’t be able to see data that might not concern them (example, an Italian team will be able to see only Italy sales data and not France sales data).

Usually, this concept is covered applying the section access, and it must be declared in the QlikSense app’s script.

Thanks to the Qlik Application Automation integration in the Qlik SaaS, there is now another way to guarantee the data segregation, the Loop and Reduce Blocks!

Firstly, my question in seeing this new feature was “why should I use the loop and reduce function if I already have the section access?” ; trying to reason with it, I suddendly understood a possible use case.

Although it can be very easy to implement a section access, we could find ourselves in the case of managing hundreds and hundreds of users, which puts a lot of demand on memory requirements; it also takes much longer to initially open the apps. This is the reason why we should use the loop and reduce function instead!

Use Case: loop and reduce one (or more) app(s) by one field are publish the reduced applications in specific spaces

In this section, the following scenario will cover multiple applications which share the same field that will be used for the data segregation.

Let’s assume we developed in a shared space two country-based sales applications on the Qlik SaaS

Qlik Shared Space – Country Apps

These are their scripts:

Country_App1 script
Country_App2 script

As you can see, they share the same field Country, which will be used on our Loop And Reduce!

We want to distribute the reduced applications in specific spaces, which should be accessed by one or more users, so we have to create as many managed spaces as the Country possible values (Italy, France, London in our case)

Firstly, let’s create a new automation, which final output is the following

Loop and Reduce automation

Now, Let’s see in the detail each phase:

List apps: you are going to iterate over all the applications in a specific space, in this case the Country_Apps shared space

Loop and reduce: for each application in the previous block, you must declare the field on which will be applied the reduce function

Variable – vspace: in this block you are going to declare the ID space you are going to publish the reduced applications on.

This variable will be mapped based on the current field value (e.g. if the current Country field value is Italy, the space you are to consider will be the Italy one)

Publish Reduced Apps: this is the most important block!

Each reduced application (example the Country_App1 with only Italy data) has its ID and it must be published

– we have to give as input its current ID and a name (in this scenario, I thought the option was giving as name the original application name followed by the reduced field value)

– since we are going to publish the reduced application, we have to consider only the public sheets

– the pubblication of a reduced application requires a space, this is achieved using the variable previously managed

Now, let’s run the automation and we’ll have 3 different Country_App1 and Country_App2 in their respective spaces:

France- managed space
Italy – managed space
London – managed space

Finally, now we can simply declare the users who are attempting to access the respective spaces!

Hope you enjoyed the reading 🙂