Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
ieuyar
Contributor III
Contributor III

Addmonths function with a negative integer

Hi all,

I'm trying to change the start date of periods from 1st day of month to 26th day of previous month.

For example, For December 2016 Period, it should be between November 26, 2016 and December 25,  2017

When I'm trying to load below, qlikview does not subtract a month but adds it.

Date(AddMonths(MonthStart(FiscalDate+25),-1), 'YYYY-MM') as Period


Could you please help me to solve this?

1 Solution

Accepted Solutions
sunny_talwar

Try this:

Table:

LOAD Date(AddMonths(FiscalDate, -1) + 25) as Date,

  Date(FiscalDate, 'YYYY-MM') as Period;

LOAD Date(MakeDate(2015, 12, 31) + IterNo()) as FiscalDate

AutoGenerate 1

While IterNo() <= 366;

View solution in original post

9 Replies
sunny_talwar

May be this:

Date(AddMonths(MonthStart(FiscalDate),-1)+25, 'YYYY-MM') as Period

ieuyar
Contributor III
Contributor III
Author

Unfortunately, it did not work.

vinieme12
Champion III
Champion III

try

Date(MonthStart(FiscalDate,-1)+25,'YYYY-MM') as Period

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
sunny_talwar

Can you share few rows of data to show what you are looking to do? what was the issue when you used your own script? What was different when you used mine?

Anonymous
Not applicable

Check if field "FiscalDate" is in date format.

ieuyar
Contributor III
Contributor III
Author

This is result according to my script:

myscipt.png

And here is according to yours:

yours.png

ieuyar
Contributor III
Contributor III
Author

It did not work.

It works this way: ,

yours2.png

vinieme12
Champion III
Champion III

what exactly do you want to show in period? you wanted to subtract a month , the expression is subtracting a month!!

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
sunny_talwar

Try this:

Table:

LOAD Date(AddMonths(FiscalDate, -1) + 25) as Date,

  Date(FiscalDate, 'YYYY-MM') as Period;

LOAD Date(MakeDate(2015, 12, 31) + IterNo()) as FiscalDate

AutoGenerate 1

While IterNo() <= 366;