Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
bouderbc
Creator
Creator

How to create a bar chart with Curent year and previous year in the same Graph ?

How to create a bar chart with Curent year and previous year in the same Graph ?

Example: Year 2017 and Year 2016 on Sum Sales amount

10 Replies
OmarBenSalem

Try this:Capture.PNG

Dimension :Year

Measure: Sum({<Year={"<= $(=max(Year))  >= $(=max(Year)-1) " }>} "Sales amount")

the graph will always return sales for the selected year and its previous one:

vinieme12
Champion III
Champion III

Option 1: one dimension one expression

Add the Year field as Dimension

Expression = Sum({<Year = {2016,2017}>}Sales)

Option 2: No dimension two expressions

Add two Expressions

Expression1 = Sum({<Year = {2016}>}Sales)

Expression2 = Sum({<Year = {2017}>}Sales)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
rahulpawarb
Specialist III
Specialist III

Hello Ali,

Trust that you are doing well!

You can me use below given sample expressions to get Current as well as Previous Year Sales Amounts in Bar Chart (Max(CalendarYear) will get the highest year value in the context of current selection😞

//Prev. Year Sales

Sum({<CalendarYear={"$(=Max(CalendarYear)-1)"}>}SalesAmount)

//Current Year Sales

Sum({<CalendarYear={"$(=Max(CalendarYear))"}>}SalesAmount)

Also refer the attached application.

Regards!

Rahul

viveksingh
Creator III
Creator III

you can write expression like

Sum({<Year = {2016,2017}>}Sales_amount)

above expression gives sales_amount for the year 2016 and 2017

bouderbc
Creator
Creator
Author

Thanx vivek , it works !!!

bouderbc
Creator
Creator
Author

Hello Rahul,

Thanx a lot !

OmarBenSalem

The expression given by Vivek will only show you bars of 2017 and 2016; if you want your expression to be dynamic and to depend on your selection;

You must do as follow:

Dimension :Year

Measure: Sum({<Year={"<= $(=max(Year))  >= $(=max(Year)-1) " }>} "Sales amount")

With that, what we're doing is telling Qlik to calculate the Sum of Sales when the year is between the selected year and the selected year-1.

So if I select 2013; I will have bar containing 2012 and 2013

if I select 2014; I will have bar containing 2013 and 2014

if I select 2017; I will have bar containing 2016 and 2017


and so on.


Hope it's rather clear now

Have a nice day, and please don't forget to close the discussion by marking one of the answers as correct


bouderbc
Creator
Creator
Author

it works but with $ 

sum({$<Year={'2015','2016'}>}Sales).

Thanx again

bouderbc
Creator
Creator
Author

ur solution will be helpful but it doesn't work , are u sur about the synthax ? thx