Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
sakshikaul
Creator II
Creator II

Addmonth function with field name

Hi,

if(Batch='A','18'&'/'&Month&'/'&Year,if(Batch='B','3'&'/'&Month&'/'&Year )) as due_date

now I want when I select a value like 18-12-2019 under the field name due date then I want output as 18-01-2020 

Please tell me for this how to use add month  function with a field name 

1 Solution

Accepted Solutions
sunny_talwar

I think you should create due_date like this

If(Batch = 'A',
    MakeDate(Year, Month, 18),
If(Batch = 'B',
    MakeDate(Year, Month, 3))) as due_date

If Month is not a number, but text, you can try this

If(Batch = 'A',
    MakeDate(Year, Month(Date#(Month, 'MMM')), 18),
If(Batch = 'B',
    MakeDate(Year, Month(Date#(Month, 'MMM')), 3))) as due_date

and then to add 1 month, you can just do this

AddMonths(due_date, 1)

View solution in original post

7 Replies
sunny_talwar

I think you should create due_date like this

If(Batch = 'A',
    MakeDate(Year, Month, 18),
If(Batch = 'B',
    MakeDate(Year, Month, 3))) as due_date

If Month is not a number, but text, you can try this

If(Batch = 'A',
    MakeDate(Year, Month(Date#(Month, 'MMM')), 18),
If(Batch = 'B',
    MakeDate(Year, Month(Date#(Month, 'MMM')), 3))) as due_date

and then to add 1 month, you can just do this

AddMonths(due_date, 1)
sakshikaul
Creator II
Creator II
Author

Hi

Its not working right for batch 'B'

Please check the attached screenshot @sunny_talwar 

sunny_talwar

Just by looking at the screenshot, I have no idea what you mean when you say it isn't working? Can you share your qvw and explain what exactly isn't working?

sakshikaul
Creator II
Creator II
Author

HI,

I have attached QVW with sample data. I am having following issue.

When I select batch 'B' following functionality is not working for batch 'B"

If(Batch = 'A',
    MakeDate(Year, Month, 18),
If(Batch = 'B',
    MakeDate(Year, Month, 3))) as due_date

But its working fine for when I am selecting batch 'A'

for eg-

I want when i select batch 'B' if credit note date is 16-12-2019 ie greater than date 15th jan then packing slip date should be shown as 3 JAN 2020 and due date @wprc should be 3 jan 2020 +30 = 3 feb 2020

simillarly if batch ='A' ,credit note date is 2-12-2019 ie less than 15 Jan then Packing slip should be 18 dec 2019 and due date @wprc should be 18 jan 2020 

so,above code is  working fine when I select  batch 'A' but not giving correct output for when I select batch='B"

Please check 

Thanks

sakshi

 

HeshamKhja
Contributor II
Contributor II

Did you add this line:

AddMonths(due_date, 1)

 ?

sunny_talwar

Is this resolved now? You marked a solution to this post which is why I ask

sakshikaul
Creator II
Creator II
Author

Yes resolved