Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

variable LET script error

Hello! Can someone explain me, please, why does

LET vMonthStart=MonthStart(max(Date));

//Date is a field of previously loaded table

cause a script line error?

Regards,

Alexa

1 Solution

Accepted Solutions
fernando_tonial
Valued Contributor

Re: variable LET script error

Hi, try this.

LET vPeriod=$(vMaxDateNum)-$(vMonthStartNum);

Best Regards.

Tonial.

18 Replies
crusader_
Valued Contributor

Re: variable LET script error

Hi,

You should use following expression:

LET vMonthStart=MonthStart(max(PEEK('Date')));


Hope this helps.


Andrei

Not applicable

Re: variable LET script error

Andrei, tahnks for your reply. But it doesn't work/ the same error=(

mato32188
Contributor III

Re: variable LET script error

Hi Alexa,

check this one

let vmax = MonthStart(Peek('DateOfSale', -1));


BR

M

crusader_
Valued Contributor

Re: variable LET script error

Hm...

So, you can try this construction:

abc:

LOAD * INLINE [

Date, Max

01.12.2015, 123

05.12.2016, 234

];

temp:

LOAD

  max(Date) as MaxDate

resident abc;

LET vMonthStart = MonthsStart(PEEK('MaxDate'));

drop table temp;

Regards,

Andrei

yduval75
Contributor III

Re: variable LET script error

Tmp_MaxDate:

Load

   Max (Date) as MaxDate

Resident Previous_Table;

LET vMonthStart=MonthStart(FieldValue('MaxDate', 1));

Not applicable

Re: variable LET script error

I made like this

TempTable1:

LOAD

Max( Date) as MaxDate

Resident FACT;

Let vMaxDateNum = Num( Peek( 'MaxDate', 0, 'TempTable1'));

Let vMaxDate = Date( $(vMinDateNum));

LET vMonthStart=MonthStart($(vMaxDate));

LET vPeriod=$(vMaxDate)-$(vMonthStart);// to tell the truth, THIS variable is what I need

There is no error.

But it DOESNT WORK=((( only first variable is ok. I cant see other variables in my option of document....

what can be wrong?=(

mato32188
Contributor III

Re: variable LET  script error

and make sure, your dates are sorted ascending

sujeetsingh
Honored Contributor III

Re: variable LET script error

Can you post a sample

Not applicable

Re: variable LET script error

Hi Alexa,

can you post an example? Peek should work for you. Though the 'max' won't work in the let like that, as peek only returns a single value, so max won't do anything.

You'll either need to load a new date field to use with the max within it, or ensure you data is order by date, so you can peek the last/first row depending on your ordering.

hope that helps

Joe

Community Browser