10 Replies Latest reply: Mar 24, 2017 10:00 AM by omar bensalem

# 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

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

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:

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

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

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

Yes, and it works for me, What is your dimension and actual measure?

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

Option 1: one dimension one expression

Add the Year field as Dimension

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

Option 2: No dimension two expressions

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

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

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

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

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

Hello Rahul,

Thanx a lot !

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

you can write expression like

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

above expression gives sales_amount for the year 2016 and 2017

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

Thanx vivek , it works !!!

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

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

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

it works but with \$

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

Thanx again