
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- « Previous Replies
-
- 1
- 2
- Next Replies »

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this:
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:


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
If a post helps to resolve your issue, please accept it as a Solution.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you can write expression like
Sum({<Year = {2016,2017}>}Sales_amount)
above expression gives sales_amount for the year 2016 and 2017

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanx vivek , it works !!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Rahul,
Thanx a lot !

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it works but with $
sum({$<Year={'2015','2016'}>}Sales).
Thanx again

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ur solution will be helpful but it doesn't work , are u sur about the synthax ? thx

- « Previous Replies
-
- 1
- 2
- Next Replies »