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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to generate dates backwards using addmonths function ?

The scenario is like this,

if i select today's date i.e 15-06-2015 the i need to generate 12 number of dates in backward manner for each month, for example

for date 15-06-2015, it should generate-

15-05-2015

15-04-2015

15-03-2015

15-02-2015

15-01-2015

15-12-2014

15-11-2014

15-10-2014

15-09-2014

.

.

.

15-06-2014




Thanks.

32 Replies
sunny_talwar

Try this:

=Concat(Date(AddMonths(Today(), ValueLoop(-1, -12, -1)), 'DD/MM/YYYY'), Chr(13), -AddMonths(Today(), ValueLoop(-1, -12, -1)))


Capture.PNG

Not applicable
Author

Thanks GGALLINA

Not applicable
Author

sunindia

actually i was wondering if we can do the same stuff, in the script itself ?

i have created a list box with 12 values associated with each date in datefield, now how can we proceed with that ?

we need to modify the 'i' value to a proper date format

Anonymous
Not applicable
Author

Hi,

do you mean this (please see attachment, listbox New i)?

Regards.

Not applicable
Author

hey,

actually we are supposed to create a new column  'new i ' for the table(in script) instead of writing an expression for the list box.

Anonymous
Not applicable
Author

Try with this, column New 1a that I created in the script.

You can also think if you want to can select only one value in Datafield listbox with a trigger.

I hope this can help you.

Not applicable
Author

Thanks a lot GGALLINA

it really helped

Anonymous
Not applicable
Author

You are welcome!

Regards.

Not applicable
Author

hey GGALLINA, can you suggest a modification for the list you generated(new 1a), can we restrict that list till the current year only ? i mean if the date is 25-04-2015 then we should go like 25-03-2015 ,25-02-2015 ,25-01-2015.

i.e we dont need dates for previous year.

sunny_talwar

May be if you use this while statement:

While IterNo() <=12 and Year(AddMonths(date(Datefield),(-1) * IterNo(),'DD/MM/YYYY')) = Year(Today());

Also attaching the qvw you guys were working with.

HTH

Best,

Sunny