Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

To create dynamic variable in Load Script so that i can create a expression in Load Script

Hello,

I was facing an issue with my data model as i have to create everything in the load script. Everything is working as expected but there is one issue that there are two variables created in the Front End like this:

vStartDate=Floor(Date(Max(AddMonths([Fiscal Date],3)),'DD-MMM-YYYY'))

vEndDate= Floor(Date(MonthEnd(Max(AddMonths([Fiscal Date],3))),'DD-MMM-YYYY'))

variable's value depends on the selection of [Fiscal Date]. I Want to d it in Script End as this is the requirement.

Can anybody suggest how to proceed.

Thanks,

Manish Rawat

hicdjklech_miszkiewicz‌  Qlik Community

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hey Petter,

It didn't worked but i somehow made a logic on the back end to summaries the Date field with the All the data (Year Month) and made a flag out of it.

It is working fine for me now.

Thanks for your support. Really appreciate it.

View solution in original post

6 Replies
petter
Partner - Champion III
Partner - Champion III

You can define them in the load script by using SET statements like this:

SET vStartDate='=Floor(Date(Max(AddMonths([Fiscal Date],3)),''DD-MMM-YYYY''))';

SET vEndDate='=Floor(Date(MonthEnd(Max(AddMonths([Fiscal Date],3))),''DD-MMM-YYYY''))';

Notice that you have to use two single quotes to get one single quotes inside a string that is delimited by single quotes.

If you don't like the double quoting you could actually write it verbatim but you must then have a space between the two equal characters:

SET vStartDate= =Floor(Date(Max(AddMonths([Fiscal Date],3)),'DD-MMM-YYYY')) ;

SET vEndDate= =Floor(Date(MonthEnd(Max(AddMonths([Fiscal Date],3))),'DD-MMM-YYYY')) ;

Anonymous
Not applicable
Author

Hey Petter,

Thank you for your reply.

How do you want me to implement this as if i declare those two variable Using SET and with using peek, then i'll be getting either Max Value or Min Value depending upon the parameter we give in Peek (0 or -1).


My Requirement:

Existing:

If user Selects Year=2018 and Month=Apr then vStart= 4/1/2018 (Num Converted to date)

and similarly vEnd=4/30/2018 . It all depends on the selection.


As it should be:

it all should happen in Load Script.


Kindly provide me the workaround to do as you suggested.

Thanks in Adv.

petter
Partner - Champion III
Partner - Champion III

If you want to get the max value of [Fiscal Date] while running the load script then you can use a Peek. Then it is not a selection in Qlik terms....

MAX_FISCAL: LOAD Max([Fiscal Date]) AS MaxFiscalDate RESIDENT <the-table-containing-Fiscal-Date>;


vStartDate=Floor(Date(AddMonths(Peek(MaxFiscalDate),3),'DD-MMM-YYYY')) ;

vEndDate=Floor(Date(MonthEnd(AddMonths(Peek(MaxFiscalDate),3),'DD-MMM-YYYY')) ;

DROP TABBLE MAX_FISCAL;

petter
Partner - Champion III
Partner - Champion III

Did this work for you?

Anonymous
Not applicable
Author

Hey Petter,

It didn't worked but i somehow made a logic on the back end to summaries the Date field with the All the data (Year Month) and made a flag out of it.

It is working fine for me now.

Thanks for your support. Really appreciate it.

petter
Partner - Champion III
Partner - Champion III

You're welcome. Please mark the question as answered to close the thread.