The following figure is of a stacked bar chart, a standard way of comparing separate entities. Each value that you select is displayed as a segment in each bar by year:
Using a comparative analysis lets you group the separate selections dynamically, so that you can compare them against each other. In the preceding example we can group together Plum and Apple versus Fig and Orange.
For the purpose of this recipe,we will make use of an inline data load which gives yearly sales information for different fruits. Load the following script in the Qlik Sense data load editor:
Data: LOAD * INLINE [ Fruit, Year, Sales Apple, 2013, 63 Apple, 2014, 4 Cherry, 2014, 1150 Cherry, 2013, 1180 Fig, 2013, 467 Fig, 2013, 374 Fig, 2014, 162 Orange, 2013, 131 Orange, 2013, 145 Orange, 2014, 102 Pear, 2014, 489 Pear, 2014, 782 Plum, 2013, 148 Plum, 2014, 412 ]; DataIslandFruit: LOAD * INLINE [ FruitAlt Apple Cherry Fig Orange Pear Plum ];
Comparison Analysis
.Group 1 Sales
:Sum(Sales)
Group 2 Sales
:Sum({<Fruit={$(=GetFieldSelections(FruitAlt))}>}Sales)
Group 1
.Group 2
.The following is an example where no selections are made:
The following is an example where selections are made:
The second table we loaded is what's known as a data island, this table is not connected to the rest of the data model in any way. However, we can use its contents in our Set Analysis expression to compare different groups of the same field.
The first expression is completely standard. The second expression gives the total sales where the Fruit field (part of the complete dataset) matches the values selected in the FruitAlt field (part of the disconnected data island). This method allows us to select groups of data for aggregation in our graph that we can not do normally by effectively breaking the association (green, white, and grey) using Set Analysis.