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

Creating a prior Month

I'm trying to create a previous month in my script.  I have a field that is "FiscalMthRelNum" that gives a number value (ex, 303 = Dec 2012).  I'd like to create a PreviousFiscalMthRelNum that would return the value "302" with the record for Dec 2012.  The "302" would indicate the previous month of Nov 2012.

Any ideas?  Again, I'm trying to create this in the script, just not sure how.

Thank you for any help!

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Just subtracting 1 from FiscalMthRelNum should do the trick:

TableX:

load

FiscalMthRelNum,

FiscalMthRelNum - 1 as PreviousFiscalMthRelNum,

...

from ...etc;

Just make sure FiscalMthRelNum is a number. If necessary make it one first: num#(FiscalMthRelNum)


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar

Just subtracting 1 from FiscalMthRelNum should do the trick:

TableX:

load

FiscalMthRelNum,

FiscalMthRelNum - 1 as PreviousFiscalMthRelNum,

...

from ...etc;

Just make sure FiscalMthRelNum is a number. If necessary make it one first: num#(FiscalMthRelNum)


talk is cheap, supply exceeds demand
Anonymous
Not applicable
Author

If you're using dates that were formatted by QlikView and each number represents 1 day rather than 1 month, I've found the AddMonths(Date,Offset) function helpful.  So in your example, if you wanted previous month, you would put the date in the first part of the expression and the offset would be -1.  But if you're generating you're own numbers for the months, then this may be overkill.