Lollipop Chart
This example recreates a yearly sales comparison with an SVG lollipop chart in Qlik: a current-year sales KPI, comparisons to a selectable baseline year and the previous year, a moving baseline line, and one lollipop per year.

See the chart in Qlik
A short screen recording of the Lollipop Chart working in a Qlik Sense app: selections change the sales values and the baseline moves when a different baseline year is picked.
This is a recording, not a live Qlik connection — the sales figures shown in it are synthetic demo data.
Design inspiration: ‘16 Different Ideas to Visualize your KPIs (opens in a new tab)’ by Kajal Kadam on Tableau Public.
This is my own SVG and Qlik adaptation of the visual idea.
What the chart shows
- Current year sales, based on the latest year in the dataset.
- Percentage comparison to a selectable baseline year.
- Percentage comparison to the previous year.
- A horizontal baseline that moves when you pick a different baseline year.
- One lollipop for every year in the
Yeardimension. - Country selections filter the sales values; Year selections do not remove years from the chart.
The sales figures are synthetic demo data, not real country sales. The Qlik script and expression below are for you to use and test in Qlik Sense. This page is not connected to a Qlik app.
Download qvf
Download the supplied Lollipop Chart Qlik app. Requires Qlik Sense to open .qvf files.
Tested with: Qlik Sense edition and version not yet confirmed.
Download sample data
Download the sales demo CSV with Country, Year, Sales and Unit fields to load into the SalesTrend table.
Set it up in Qlik
- 1Load the
Country,Year,SalesandUnitfields into a table calledSalesTrend. - 2After loading
SalesTrend, add the disconnectedBaselineYearPickertable and the variables from the load script shown under this step.Lollipop Chart — Qlik load scriptSalesTrend: LOAD Country, "Year", Sales, Unit FROM [lib://DataFiles/SVG_Sales_Trend_Country_Demo.csv] (txt, codepage is 28591, embedded labels, delimiter is ',', msq); BaselineYearPicker: LOAD DISTINCT Year as BaselineYear RESIDENT SalesTrend; // Find the latest year in the loaded data YearMax: LOAD Max(Year) as MaxYear RESIDENT SalesTrend; LET vCurrentYear = Peek('MaxYear', 0, 'YearMax'); LET vPreviousYear = $(vCurrentYear) - 1; DROP TABLE YearMax; // Sales KPIs SET vCurrentSales = Sum({<Year={$(vCurrentYear)}>} Sales); SET vPreviousSales = Sum({<Year={$(vPreviousYear)}>} Sales); // Use the selected baseline year; default to 2021 SET vBaselineYear = If(GetSelectedCount(BaselineYear)=1, Only(BaselineYear), 2021); SET vBaselineSales = If( GetSelectedCount(BaselineYear)=1, Sum({<Year=BaselineYear>} Sales), Sum({<Year={2021}>} Sales) ); // Chart scaling and coordinates SET vAnnualMax = Max(TOTAL Aggr({<Year=>} Sum(Sales), Year)); SET vYearX = 18 + 344 * (Year - Min({<Year=>} TOTAL Year)) / RangeMax(1, Max({<Year=>} TOTAL Year) - Min({<Year=>} TOTAL Year)); SET vYearY = 280 - 145 * Sum(Sales) / $(vAnnualMax); SET vBaselineY = 280 - 145 * $(vBaselineSales) / $(vAnnualMax); SET vScaleMax = $(vAnnualMax); SET vScaleStep = $(vScaleMax)/5;Paste into the Qlik data load editor — see step 2 above.
- 3Add a Qlik filter pane using the
BaselineYearfield. - 4Paste the SVG expression below into Qlik using either method from the SVG Basics lesson: Method 1, a Button object, or Method 2, an Image object.
- 5The baseline defaults to 2021 until exactly one baseline year is selected in the filter pane.
- 6Country selections change the sales values. Year filter selections do not remove years from the lollipop chart, because the marks ignore Year selections with
{<Year=>}.
Qlik SVG expression
Multiline, joined with &, with percent-encoded colours.
='data:image/svg+xml;utf8,' &
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 380 330" width="100%" height="100%">' &
'<text x="370" y="30" text-anchor="end" font-family="Arial" font-size="17" fill="%231d4f91">' &
'Current Year Sales: £' & Num($(vCurrentSales)/1000000,'0.00') & 'M</text>' &
'<text x="370" y="60" text-anchor="end" font-family="Arial" font-size="14" fill="%2375b843">' &
Num($(vCurrentSales)/$(vBaselineSales)-1,'0.0%') &
If($(vCurrentSales)>=$(vBaselineSales),' above Baseline Year ',' below Baseline Year ') &
'(' & $(vBaselineYear) & '): £' &
Num($(vBaselineSales),'#,##0') &
'</text>' &
'<text x="370" y="86" text-anchor="end" font-family="Arial" font-size="14" fill="%23c2185b">' &
Num($(vCurrentSales)/$(vPreviousSales)-1,'0.0%') &
If($(vCurrentSales)>=$(vPreviousSales),' above Previous Year ',' below Previous Year ') &
'(' & $(vPreviousYear) & '): £' &
Num($(vPreviousSales),'#,##0') &
'</text>' &
'<line x1="12" x2="368" y1="' &
Num($(vBaselineY),'0.0','.','') &
'" y2="' &
Num($(vBaselineY),'0.0','.','') &
'" stroke="%2300b9e8" stroke-width="3"/>' &
'<text x="14" y="' &
Num($(vBaselineY)-8,'0.0','.','') &
'" font-family="Arial" font-size="12" fill="%2300a6d2">' &
'Baseline Year ' & $(vBaselineYear) &
'</text>' &
Concat(
Aggr(
{<Year=>}
'<line x1="' & Num($(vYearX),'0.0','.','') &
'" y1="280" x2="' & Num($(vYearX),'0.0','.','') &
'" y2="' & Num($(vYearY),'0.0','.','') &
'" stroke="%23888888" stroke-width="1.5"/>' &
'<circle cx="' & Num($(vYearX),'0.0','.','') &
'" cy="' & Num($(vYearY),'0.0','.','') &
'" r="6" fill="%23c8c8c8" stroke="%23888888"/>' &
'<text x="' & Num($(vYearX),'0.0','.','') &
'" y="305" text-anchor="middle" font-family="Arial" font-size="12" fill="%23555555">' &
Year & '</text>',
(Year,(NUMERIC,ASCENDING))
),
''
) &
'</svg>'Paste into the Qlik image expression editor — see step 4 above.
The same expression with a comment above each part, explaining what it does. For reading only — Qlik chart expressions do not accept comments, so paste the uncommented version above into Qlik.
// Lollipop Chart — Qlik expression, explained line by line.
// NOTE: comments (// ...) are for reading only. Paste the uncommented
// version above into Qlik — chart expressions do not accept comments.
// Start the data URL that tells Qlik this text is an SVG image.
='data:image/svg+xml;utf8,' &
// Open the SVG canvas: 380 x 330 units, stretched to fill the object.
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 380 330" width="100%" height="100%">' &
// --- KPI line 1: current year sales, top right, in millions (£M) ---
'<text x="370" y="30" text-anchor="end" font-family="Arial" font-size="17" fill="%231d4f91">' &
'Current Year Sales: £' & Num($(vCurrentSales)/1000000,'0.00') & 'M</text>' &
// --- KPI line 2: % vs the baseline year (green), with the baseline value ---
'<text x="370" y="60" text-anchor="end" font-family="Arial" font-size="14" fill="%2375b843">' &
Num($(vCurrentSales)/$(vBaselineSales)-1,'0.0%') &
If($(vCurrentSales)>=$(vBaselineSales),' above Baseline Year ',' below Baseline Year ') &
'(' & $(vBaselineYear) & '): £' &
Num($(vBaselineSales),'#,##0') &
'</text>' &
// --- KPI line 3: % vs the previous year (pink), with its value ---
'<text x="370" y="86" text-anchor="end" font-family="Arial" font-size="14" fill="%23c2185b">' &
Num($(vCurrentSales)/$(vPreviousSales)-1,'0.0%') &
If($(vCurrentSales)>=$(vPreviousSales),' above Previous Year ',' below Previous Year ') &
'(' & $(vPreviousYear) & '): £' &
Num($(vPreviousSales),'#,##0') &
'</text>' &
// --- Horizontal baseline line at the baseline year's sales height ---
'<line x1="12" x2="368" y1="' &
Num($(vBaselineY),'0.0','.','') &
'" y2="' &
Num($(vBaselineY),'0.0','.','') &
'" stroke="%2300b9e8" stroke-width="3"/>' &
// --- Baseline label, drawn 8 units above the line, left aligned ---
'<text x="14" y="' &
Num($(vBaselineY)-8,'0.0','.','') &
'" font-family="Arial" font-size="12" fill="%2300a6d2">' &
'Baseline Year ' & $(vBaselineYear) &
'</text>' &
// --- One lollipop per Year, built by looping over the Year dimension ---
// Aggr runs the inner text once per Year; {<Year=>} keeps every year
// visible even when a Year filter is selected; Concat joins the pieces.
Concat(
Aggr(
{<Year=>}
// Stem: vertical line from the floor (y=280) up to the value.
'<line x1="' & Num($(vYearX),'0.0','.','') &
'" y1="280" x2="' & Num($(vYearX),'0.0','.','') &
'" y2="' & Num($(vYearY),'0.0','.','') &
'" stroke="%23888888" stroke-width="1.5"/>' &
// Head: grey dot at the top of the stem.
'<circle cx="' & Num($(vYearX),'0.0','.','') &
'" cy="' & Num($(vYearY),'0.0','.','') &
'" r="6" fill="%23c8c8c8" stroke="%23888888"/>' &
// Year label under the floor line, centred on the stem.
'<text x="' & Num($(vYearX),'0.0','.','') &
'" y="305" text-anchor="middle" font-family="Arial" font-size="12" fill="%23555555">' &
Year & '</text>',
(Year,(NUMERIC,ASCENDING))
),
''
) &
// Close the SVG.
'</svg>'Reading only — paste the uncommented expression into Qlik (step 4 above).
Explain this code
Loading the disconnected baseline-year picker
BaselineYearPicker copies every Year into a new field, BaselineYear. It shares no field name with SalesTrend, so selecting a baseline year does not filter the sales data — it only tells the variables which year to compare against.
Finding the latest year and previous year
YearMax holds the highest Year in the data. Peek reads it into vCurrentYear, vPreviousYear is one less, and the helper table is dropped. These are fixed when the script reloads.
The baseline and KPI variables
vCurrentSales and vPreviousSales sum Sales for those two years. vBaselineYear and vBaselineSales use the selected BaselineYear when exactly one is selected, otherwise 2021. Because they are SET, Qlik evaluates them inside the chart, so country selections still apply.
Scaling and positioning the chart
vAnnualMax finds the largest yearly total, ignoring Year selections. vYearX spreads years evenly from x=18 to x=362. vYearY and vBaselineY map sales onto a 145-pixel tall area whose floor sits at y=280.
Drawing the baseline and lollipop marks
A 3-pixel blue line is drawn at vBaselineY with its label just above it. Concat(Aggr(…, Year)) then builds one stem line, one dot and one year label per Year, sorted ascending, and joins them into the SVG.
