Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Q&A with Qlik - Qlik Cloud Migration: Questions about migrating to Qlik Cloud? Catch the latest replay!
cancel
Showing results for 
Search instead for 
Did you mean: 
annabergendal
Partner - Creator
Partner - Creator

Sales selected months last year

How can I get sales for selected period last year?

If user selects 2015-03, how can I get sales for 2014-03?

See attached,

Thanks!

Labels (1)
1 Solution

Accepted Solutions
tresB
Champion III
Champion III

For multiple months selection try like:

=sum({<YeasrMonth={$(vPreYrMonths)}>}Sales)

where,

vPreYrMonths =Concat( DISTINCT chr(39)&(Left(YeasrMonth,4)-1)&'-'&Right(YeasrMonth,2)&chr(39) , ',')

PFA

View solution in original post

11 Replies
sunny_talwar
MVP
MVP

Try this expression:

=If(Sum(Sales) > 0, Above(Sum({<YeasrMonth=>}Sales)))

annabergendal
Partner - Creator
Partner - Creator
Author

Thanks,

but that does not work.

It gives me previous months sales, not previous year current months sales.

Anonymous
Not applicable

For this kind of comparisons, I always calculate a "MonthID" in the script:

(num(Year(Date))-1)*12 + Month(Date) as MonthID

In your expressions you can use afterwards:

Sum({$<MonthID = {$(=Max(MonthID)-12)} >} Amount) for month in previous year

Sum({$<MonthID = {$(=Max(MonthID))} >} Amount) for month in current year

Hope this helps!!

tresB
Champion III
Champion III

=sum({<YeasrMonth={"$(=Left(YeasrMonth,4)-1&'-'&Right(YeasrMonth,2))"}>}Sales)

tamilarasu
Champion
Champion

Hi Anna,

Try,

sum({<YeasrMonth={"$(=Date(Addmonths(Date#(YeasrMonth,'YYYY-MM'),-12),'YYYY-MM'))"}>}Sales)

!

annabergendal
Partner - Creator
Partner - Creator
Author

Thanks,

but none of these work for selection of several months.

Not applicable

try is

=SUM({<YearMonth={"$(=Date(Addmonths(Date#(YearMonth,'YYYY-MM'),-12),'YYYY-MM'))"}>}Sales)

Anonymous
Not applicable

try this:

At script level in your calender table, create this first:

Year*12 + num(Month(Date)) as MonthID

In your expressions you can use afterwards:

=Sum({<MonthID = {'=$(=Max(MonthID)-12)'} >} Amount) for month in previous year

=Sum({<MonthID = {'=$(=Max(MonthID))'} >} Amount) for month in current year

Hope this will help!!

tresB
Champion III
Champion III

For multiple months selection try like:

=sum({<YeasrMonth={$(vPreYrMonths)}>}Sales)

where,

vPreYrMonths =Concat( DISTINCT chr(39)&(Left(YeasrMonth,4)-1)&'-'&Right(YeasrMonth,2)&chr(39) , ',')

PFA