Qlik Community

Ask a Question

Qlik Design Blog

All about product and Qlik solutions: scripting, data modeling, visual design, extensions, best practices, etc.

Announcements
Join us March 10th, 7 Ways Modern Analytics Can Help You Take Smarter Action. REGISTER NOW
Jennell_McIntire
Employee
Employee

The Demo Team recently built a mashup for the 2016 Oscars where we analyzed the nominees and award winners over the past 88 years.  The design for the mashup often showed nominees and winners in the same chart as seen below where the silver bar indicated nominations and the gold bar represented wins.

Example of bar charts.png

One requirement for the app was to color the number of nominations bar silver and the number of wins bar gold.  In the data model, we did not have a field that we could use as the dimension to show the coloring for nominations and winner so at the suggestion of Alexander Karlsson we used the ValueList chart function.  As noted in Qlik Sense Help, “ValueList() returns a set of listed values, which, when used in a calculated dimension, will form a synthetic dimension.”  In the Actresses bar chart above, we created the dimension using this syntax:

ValueList('Oscars', 'Nominations')

Thus creating a synthetic dimension with two possible values: Oscars and Nominations.  Then in the measure, we used an If statement to assign a measure to each list item in our ValueList dimension.

If(ValueList('Oscars', 'Nominations')='Oscars',

     Count({<Actress_Win_flg={'1'} >} Distinct Film),

     (Count(Distinct Film)-Count({<Actress_Win_flg={'1'} >} Distinct Film)))

If the dimension is ‘Oscars’ then we count the films where the actress won.  Otherwise, we count the nominations where the actress did not win.  This same logic was used to handle the coloring of the bars.  We colored the bars by using this expression:

If(ValueList('Oscars', 'Nominations')='Oscars', '#e1aa3d', '#ccc')

If the dimension is Oscars showing the wins, then color the bar gold otherwise color the bar silver.

The ValueList chart function provided what we needed to treat nominations and winners as if they were a dimension providing us the flexibility to vary the measures and coloring we wanted to use on the bars in the bar chart.  This solution saved us time from having to modify our data model to accommodate our design requirements.  The only difference between the ValueList synthetic dimension and a normal dimension is synthetic dimensions are not affected by selections.  Alexander Karlsson wrote a blog about ValueList as well as ValueLoop – check it out.

Thanks,

Jennell

9 Comments
Jennell_McIntire
Employee
Employee

Naresh,

Yes, a variable can replace the measure.  In place of the measure, simply enter $(variablename).

Jennell

0 Likes
1,000 Views
prasoon1852
Contributor
Contributor

Hey jmc ,

How can i restrict my dimension to show only top 10 values in this case ? I tried all possible ways but nothing is working.

Prasoon

0 Likes
1,000 Views
Jennell_McIntire
Employee
Employee

Hi Prasoon,

You can set a limit on the dimension (like the Actor or Actress in my example).  In the properties for the dimension, under Limitation, you can select Fixed number and set it to Top 10.

Hope this helps.

Jennell

0 Likes
1,000 Views