The tree maps (previously called block charts in Qlikview) are a good way to show how different parts combine to form the whole. To add more depth to the visualization, you can easily highlight areas of importance by adding color codes.
For this recipe, we will make use on inline data load which gives the product sales information. Load the following code into the data load editor:
LOAD * INLINE [ Product Line, Product Group, Product Sub Group, Year, Sales, Cost Drink, Beverages, Juice, 2015, 12000, 6000 Drink, Beverages, Juice, 2014, 16000, 7000 Drink, Beverages, Soda, 2015, 42000, 26000 Drink, Beverages, Soda, 2014, 68000, 57000 Drink, Beverages, Water, 2015, 18000, 8000 Drink, Beverages, Water, 2014, 10000, 6000 Drink, Dairy, Milk, 2015, 25000, 22000 Drink, Dairy, Milk, 2014, 22000, 20000 Food, Dairy, Cheese, 2015, 22000, 8000 Food, Dairy, Cheese, 2014, 31000, 30000 Food, Produce, Nuts, 2015, 50000, 30000 Food, Produce, Nuts, 2014, 46000, 26000 Food, Produce, Tofu, 2015, 26000, 21000 Food, Produce, Tofu, 2014, 15000, 7000 Food, Snacks, Chips, 2015, 31000, 6000 Food, Snacks, Chips, 2014, 15000, 9000 Food, Snacks, Dips, 2015, 10000, 6000 Food, Snacks, Dips, 2014, 6000, 3000 ];
Sum(Sales)
as a measure and label it Sales
.If(Sum({<Year={2014}>}Sales)>Sum({<Year={2015}>}Sales), Red(),Green())
The tree map object groups the data based on the order of the dimensions you added. By adding the color coding expression we can quickly see the products that are doing better this month compared to the previous month.
The red and green indicators used in the preceding image can be useful to spot products that are not performing in-line with similar products. To get more value from these type of indicators, we can change the density of the color to reflect the magnitude of change.
Replace the color expression we used in step 7 of How to do it... with the following code:
If((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales)>0, ColorMix1((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales), white(),RGB(50,255,50)), if((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales)<0, ColorMix1(fabs((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales)), white(),RGB(255,50,50))))
The chart should now resemble the following image:
Based on the values returned by the expression, the ColorMix
function automatically assigns a range of colors. In the preceding example, we have set up two color ranges; the first If
statement goes from white to green for the positive numbers and the second goes from white to red for the negative numbers. The ColourMix
function only works with positive numbers, so we use the Fabs
function to convert the negatives into positives once they are identified by the second If
statement.