Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to get recent 10 months on trend chart

Hello experts,

1. I have to plot a trend chart of sales for RECENT 10 months where as i have total 15 months.

2. my X-axis is xdate (5/1/2013,4/1/2013,3/1/2013.....and so on) and my Y-axis as expression which shows sales

my problem is how will i get recent 10 months out of 15 months? where as i have to ignore oldest 5 months.

Regards,

Santosh

8 Replies
jvitantonio
Luminary Alumni
Luminary Alumni

Hi, you need to use set analysis. Put this in your expression:

sum( {$<Date = {">=$(=AddMonths(Today()),-10)"} >} Sales )

Not applicable
Author

You can try something like this in the expression in the chart:

sum( {<YearMonth_Sequential={">=$(=max(YearMonth_Sequential)-10)"} >} field)

This will react to the user selections and will always show the most recent 10 YearMonths.

Note: YearMonth is a field containing a sequential number for your YearMonths, with a +1 increment. This way it will work even with the last and first months of the year. You can create this field in the script by doing something like:

LOAD

...

Year * 12 + Month as YearMonth_Sequential,

...

It should look like this in your table (example for 2012 and 2013):

YearMonthYearMonth_Sequential
2012124145
2012224146
2012324147
2012424148
2012524149
2012624150
2012724151
2012824152
2012924153
20121024154
20121124155
20121224156
2013124157
2013224158
2013324159
2013424160
2013524161
2013624162
2013724163
2013824164
2013924165
20131024166
20131124167
20131224168

Kind Regards,

Borja

Not applicable
Author

Hi thanks for your replies, but it is returning me only 10th month.

Here is the field name and the date format which i am using, hope it help you guys better.

Month_Desc

1/1/2012

2/1/2012

3/1/2012

4/1/2012

5/1/2012

6/1/2012

7/1/2012

8/1/2012

9/1/2012

10/1/2012

11/1/2012

12/1/2012

1/1/2013

2/1/2013

3/1/2013

Regards,

Santosh

Not applicable
Author

If you are using only that date field, you should go with the solution provided by qlikuser14. Also, check that the values are integer internally and not alphanumeric (they will be numeric if your DateFormat matches that M/D/YYY format).

In order to use my solution you should modify the script and reload the app so you can use the new field with the sequential month number.

Not applicable
Author

Hi... thanks for your reply.

Here is the field name and the date format which i am using, hope it help you

Month_Desc

1/1/2012

2/1/2012

3/1/2012

4/1/2012

5/1/2012

6/1/2012

7/1/2012

8/1/2012

9/1/2012

10/1/2012

11/1/2012

12/1/2012

1/1/2013

2/1/2013

3/1/2013

Regards,

Santosh

jvitantonio
Luminary Alumni
Luminary Alumni

Make sure you format your date in your load statement like

LOAD

Date(Month_desc,'DD/MM/YYYY') as Month_Desc

FROM...

Not applicable
Author

qlikuser14,

i formatted Month_Desc in 'DD/MM/YYYY' format as u suggested but it is returning me all the months. it is not filtering for recent 10 months. here is my expression.

sum( {$<Month_Desc = {">=$(=AddMonths(Month_Desc),-10)"} >} Sales )

Regards,

Santosh

shree909
Partner - Specialist II
Partner - Specialist II

Hi,

i think the month description is in DD/MM/YYYY format whereas the

$(=AddMonths(Month_Desc),-10)"}  is returning the number , so monthdesciption and variable value are not matching.

either u change the monthdescritption to number or

use the below expression

$(=Date(AddMonths(Month_Desc),-10),'DD/MM/YYYY')

sum( {$<Month_Desc = {">=$(=Date(AddMonths(Month_Desc),-10),'DD/MM/YYYY')"} >} Sales )

Thanks