Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to Get Prev Month Value

Hi All,

I need to get Previous Month Value when i make a selection, but struggling to get it right?

E.g if i select May on a list box it must show me values for April.

like -1

i Tried:

=sum({<Dates={'>=$(=only(Dates)-2)<=$(=only(Dates))'}>}Sales)

and

=sum( {$<Year = {$(=Only(Year)-1)}>} Sales )

im i missing something in here?

Regards:

Thabiso

11 Replies
avinashelite

try like this:

sum({<Month_Name={'>=$(monthname(monthname(date)-1)'}>}Sales)


and

=sum( {$<Year = {"$(=(Year-1)"}>} Sales )

Not applicable
Author

Hi,

What do you mean in Month_Name? and what should i use as a Dimension?

sunny_talwar

Are you trying to do this on a chart where Month is your dimension? If yes than you will have to use Above() function. If not then this should work:

=Sum({<Dates={">=$(=Date(AddMonths(Max(Dates), -1), 'DatesFieldFormat')) <= $(=Date(Max(Dates)))"}>} Sales)


or

=Sum({<Dates={"$(='>=' & Date(AddMonths(Max(Dates), -1), 'DatesFieldFormat') & '<=' & Date(Max(Dates)))"}>} Sales)

qlikmsg4u
Specialist
Specialist

That is why it is better to post sample app, to understand better by the community members. no offence.

Not applicable
Author

Hi All,

i want to use it on a Straight Table, so i just need sample Test so that i can Apply it on my Large Data Set, i created a Sample Model.

Regards.

sunny_talwar

Can you share your sample with us? It will be easier to understand your structure and give you recommendations.

Best,

Sunny

martin_dideriks
Partner - Contributor III
Partner - Contributor III

Do you just want the value for april when you select april?

Then it is:

sum({$<Year,Month,Date={">=$(=MonthStart(Min(Date),-1))<=$(=MonthEnd(Min(Date),-1))"}>} SalesAmount)

If you want to show the value for april next to may in a seperate column like this:

Month     Sales          Sales Last Month

April          

May

Jun

Then i suggest that you take a look at this post, where I do somethng similar:

Re: Last Year and Current Year Sales in Current Year Only

//Martin

Not applicable
Author

Hi,

Sample Data:

DayMonthDateDatesYearSales
10Jan2015-01-102015100
24Feb2015-02-24201523
24Mar2015-03-24201545
10May2015-05-102015345

Listbox:

MonthDate:

Jan

Feb

Mar

Apr

May

Jun

So if i select Mar it must show me values for Feb.....and if i select Feb it must show values for Jan.....and so on

Hope this will help

Thanks

Not applicable
Author

Hi,

Basically it has to calculate for Previous Month

e.g if i press Jun, it must give me sales for May

Thanks.