Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
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
Employee
Employee

Hi, try this.

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

Best Regards.

Tonial.

Don't Worry, be Qlik.

View solution in original post

18 Replies
crusader_
Partner - Specialist
Partner - Specialist

Hi,

You should use following expression:

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


Hope this helps.


Andrei

Not applicable
Author

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

mato32188
Specialist
Specialist

Hi Alexa,

check this one

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


BR

M

ECG line chart is the most important visualization in your life.
crusader_
Partner - Specialist
Partner - Specialist

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
Partner - Creator III
Partner - Creator III

Tmp_MaxDate:

Load

   Max (Date) as MaxDate

Resident Previous_Table;

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

Not applicable
Author

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
Specialist
Specialist

and make sure, your dates are sorted ascending

ECG line chart is the most important visualization in your life.
sujeetsingh
Master III
Master III

Can you post a sample

Not applicable
Author

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