How do I change polygon colors based on a variable?
Create a variable
In this example the variable will be vExpression. vExpression will have no value set by default.
Create 2 buttons to change the variable
Set an Action on one button to 'Set Variable' vExpression equal to the first expression that will be used to modify the colors of the map.
In the example, vExpression is set to Sum(Receipts). In the button not shown, vExpression is set to Count(SalesmanName).
Create a Polygon / Lines map
Add a 'Dimension' and 'Boundary / Path' to the map object.
In the example, 'Zip' is the 'Dimension' and 'ZipBoundary' is the 'Boundary / Path'. By default, QlikMaps creates an autocolor scheme that causes the map to look like the example.
Modify the 'Fill Color' expression box
Click on the 'Fx' button on the 'Fill Color' expression box to open the Expression Editor Box. Add an IF() statement that evaluates to a color.
In the example, code has been set to evaluate the expression set by the button against the average of the expression set by the button. When a button is selected, $(vExpression) is replaced by the value set by the button. Depending upon the value, either RGB(253,174,107) (orange), or RGB(57,147,198) (blue) is returned.
Change Polygons using an expression in a multilayer object
Changing polygon colors using an expression in a multilayer object requires an additional step.
Multilayer maps do not automatically update if the source object contains a variable.
An easy workaround is to force the multilayer map to re-evaluate itself based upon the same variable. Below is an example of how to force the multilayer map to re-evaluate.
=if(len($(vExpression))>0,'')