in this Qlik Tuesday tips and tricks
video
Christof Schwarz will show you how to properly sort stacked bar charts
Yes, thank you!
so let's get started by
creating actually a bar chart
we drag a new bar chart to a new sheet
and we add Product group as a dimension
and Sales as the measure
it sorts
descending by sales
and now let's add a subgroup as a second dimension
and let's stack the bar chart
and you
see now that it's sorts by alphabetical order
and if you try to move Sales in
the sorting options to the top
it just won't go there
so we have to get the formula
out of the measure
by unlinking the master item
at least for a moment
so we
steal the formula
copy it to the clipboard
then undo it, it is a master
item again
and then we go to the sorting options
and sort by expression
and when you paste the formula, then it's
sort again by sales descending
so, what we did is actually we first
moved
a master item as the charts main expression
and it's using the formula
just from there
the sort expression however needs a formula directly edited
so we duplicated it the same measure
To fix that and have a single definition of
the measure
we have to introduce variables
so, if you used a formula in a
variable
and then refer to that variable from the master item
and also from the
sort expression
you again have a single definition of a measure
In real life, you
find the variables down there
you create  a new variable
we paste the definition
there
and then we go back to the sort expression
and now we use in the syntax
 $(vSales)
we use the variable definition
And we do exactly the same in the central definition of the measure
$(vSales)
and save this and
there you go
and this concludes my Tuesday tips video
