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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Addmonths function can't work

Dear All,

I create a variable (New Time) which have value 2016-9-30 and put it in addmonths function but it failed.

However when i replace (New Time) with '2016-9-30', it work..

Case 1

Addmonths('2016-9-30', 1) = 30/10/2016 it work

Case 2

Addmonths([New Time], 1) = -  it failed which [New Time]=2016-9-30


Please help T^T

9 Replies
Anil_Babu_Samineni

Case 1

Addmonths('2016-9-30', 1) = 30/10/2016 it work

It should work because this is a static

Case 2: Try like below

Addmonths(Date([New Time],'DD/MM/YYYY'), 1)


Update: If variable, you may create something like this


AddMonths('$([New Time])',1) //Can you confirm how do you create New Line to get that Date

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

is [New Time] a variable or a field?

Are you using addmonths in script or in a chart?

Anonymous
Not applicable
Author

if its a variable:

=AddMonths('$(New Time)',1)

jonathandienst
Partner - Champion III
Partner - Champion III

You need quotes around the variable:

Addmonths('[New Time]', 1)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Hi

It doesn't work...

New Time should be a field

I create New Time in script:

year,
month,
Timestamp#(year &'-'& month &'-30','YYYY-MM') as "New Time",

year and month is the original field

Not applicable
Author

Hi

New Time should be a field

I create New Time in script:

year,
month,
Timestamp#(year &'-'& month &'-30','YYYY-MM') as "New Time",

year and month is the original field

I have tried =AddMonths('$(New Time)',1) and it doesn't work...

Anonymous
Not applicable
Author

Hi,

This should work:


DateTest:
LOAD
year,
month,
Monthend(Date#(year &'-'& month &'-01','YYYY-MM-DD')) as [New Time],
addmonths(Monthend(Date#(year &'-'& month &'-01','YYYY-MM-DD')),1) as [New Time Addmonths];
LOAD * INLINE [
year, month
2016, 01
2016, 02
2016, 03
2016, 04
2016, 05
2016, 06
]
;

Just modify and apply to your scenario.

- Use monthend function instead to determine last date of a month - Not all months have 30 days

Hope this helps!

sdmech81
Specialist
Specialist

HI,

Use makedate function and generate date as u desire

U have used like :Timestamp#(year &'-'& month &'-30','YYYY-MM') as "New Time"

And Timestamp# is interpretation-function not date generation function.

Use makedate() and then try Addmonth() it should work!

Sachin

sdmech81
Specialist
Specialist

Examples fr make date:

MakeDate(YYYY [ , MM [ , DD ] ] )

Returns a date calculated from the year YYYY, the month MM and the day DD.

If no month is stated, 1(January) is assumed.

If no day is stated, 1 (the 1:st) is assumed.

Examples:

makedate(1999) returns 1999-01-01

makedate(99) returns 0099-01-01

makedate(1992,12) returns 1992-12-01

makedate(1999,2,14) returns 1999-02-14