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: 
qlikviewforum
Creator II
Creator II

Adding month to the Variable

I have a variable called zDates='2016_07'. I need to check whether QVD's with the date already exists in appropriate location or not.

Name of the QVD will be as below.

Employee_M.2016_05.qvd
Employee_M.2016_06.qvd

In this case since 2016_07 qvd does not exists in the file system I need to add that date to the variable. So the variable now should have zDates='2016_07','2016_06'.

If the value in the variable is zDates='2016_06' then there wont be any changes in the varaible it will remain same. That is zDates='2016_06'

If the file system contains below qvd's and the variable zDates='2016_01' then in that case the variable should be updated to zDates='2015_12',2016_01'

Employee_M.2016_11.qvd

Employee_M.2016_12.qvd


Can someone help me to achieve this?

32 Replies
qlikviewforum
Creator II
Creator II
Author

error was because I removed the single quotes earlier

if(replace('$(zDates)','_','')

Now the error is not coming up but not getting expected out put.

If I don't have 2017_07 qvd then output should zSecondLoadDates='2016_07','2016_06'. but currently it is coming up as zSecondLoadDates=2016_07. Also single quotes missing.

adamdavi3s
Master
Master

Ok:

I don't understand why you need two values in the variable, that wasn't in your original post and I don't think this idea will work with that.

If you just want to add one value with single quotes then its very simple, just use chr(39)

let zDates = if(replace('$(zDates)','_','') = $(zTest), //is the max value equal to existing variable?

chr(39)& left('$(zDates)',4)&'_'&right('$(zDates)',2)&chr(39), //if so then leave it alone

chr(39)& left($(zTest),4)&'_'&right($(zTest),2))&chr(39); //otherwise set to max value

qlikviewforum
Creator II
Creator II
Author

Sorry if I have not properly communicated. But I guess I mentioned in my first post as below,

Yes we need to values in the variable. That is what the requirement is.

----

I have a variable called zDates='2016_07'. I need to check whether QVD's with the date already exists in appropriate location or not.

Name of the QVD will be as below.

Employee_M.2016_05.qvd
Employee_M.2016_06.qvd

In this case since 2016_07 qvd does not exists in the file system I need to add that date to the variable. So the variable now should have zDates='2016_07','2016_06'.

If the value in the variable is zDates='2016_06' then there wont be any changes in the varaible it will remain same. That is zDates='2016_06'

If the file system contains below qvd's and the variable zDates='2016_01' then in that case the variable should be updated to zDates='2015_12',2016_01'

Employee_M.2016_11.qvd

Employee_M.2016_12.qvd

---

adamdavi3s
Master
Master

Ok have to ask, what is the purpose of this variable as it doesn't seem like the best way of doing this...

qlikviewforum
Creator II
Creator II
Author

The reason why we need 2 months is since data comes in weekly basis there may be some cases last week of jun data and 1st of jul comes  in the month of Jul. As we are storing it as a mothly qvd we need to had both the months in the variable as we will have to generate the qvds for both the months.

qlikviewforum
Creator II
Creator II
Author

I know this is not the right way to handle this. But since we don't want to touch the existing architecture we are doing in this way else this could have been done very easily.

So it is creating lots of confusion here.

adamdavi3s
Master
Master

Don't worry we've all been in the same situation!

I'm just trying to wrap my brain around the code you need in this case.

qlikviewforum
Creator II
Creator II
Author

Thank you so much for your understanding and time. I am also thinking on it. Please let me know if you have something.

qlikviewforum
Creator II
Creator II
Author

How about below one mate?

If zSecondLoadDates=zDates then
LET zSecondLoadDates=zDates;
else
LET zSecondLoadDates=zSecondLoadDates&chr(44)&zDates;
end if

adamdavi3s
Master
Master

Adding the variable to itself is the way to add the new value, but then your test won't work as you're comparing one item to two

e.g. your zSecondLoadDates will have one value in it so it will never match zDates which has two items in it and it will just keep appending itself!

Sorry I am a bit manic this morning but I'll have a think, it should be possible to amend the original code to work for sure