Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
PradeepK
Creator II
Creator II

Dynamic Set expressions

Just exploring.. Set expressions and code maintenance  & re-usability aspect..  

Is there any other/better way to maintain and reuse set expressions.. ?

Below is sample example I have created to demonstrate the current setup..

 

//Base Sales expression
vSales = Sum( { <Active = {1}, $1, $2 >} Sales)
//Product P1 Sales
vSalesP1 = vSales(Product = {'P1'})
//Region R1 Sales
vSalesR1 = vSales(Region = {'R1'})
//Region R1 Sales and Department D1
vSalesD1R1= vSales( Region = {'R1'}, Department= {'D1'} )

 

 

Labels (3)
1 Solution

Accepted Solutions
marcus_sommer

To use a variable like vSales could be quite useful but creating a whole bunch of them like in your example for (nearly) each combination of products/region/department/whatever is the opposite - what would be the benefit against writing the expressions directly? Beside this your approach based of the nesting of variables - in general it's possible but often it creates more complexity as it solved - therefore I don't recommend it (at least not as a general way to apply expressions).

- Marcus

View solution in original post

2 Replies
skamath1
Creator III
Creator III

One way is to assign the set expression in a variable and then use $-sign expansion. 

For example 

Sum( {< $(xSetRegion) ,  $(xSetDepartment)  >} Sales)     

where variable xSetRegion  is assigned value Region = {"R1"}, and xSetDepartment is assigned value  Department = {"D1"} 

You can reuse the variable in other expressions.

marcus_sommer

To use a variable like vSales could be quite useful but creating a whole bunch of them like in your example for (nearly) each combination of products/region/department/whatever is the opposite - what would be the benefit against writing the expressions directly? Beside this your approach based of the nesting of variables - in general it's possible but often it creates more complexity as it solved - therefore I don't recommend it (at least not as a general way to apply expressions).

- Marcus