Qlik Community

Qlik Education Discussions

Discussion Board for collaboration related to Qlik Education.

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

5 Replies

Re: variable LET script error

It seems correct statement check the date format of Date field

try for check

=MonthStart(max(Today()))

Regards

Anand

Not applicable

Re: variable LET script error

Anand, thak you for your answer!

I tried to fix it..

With code like this

TempTable1:

LOAD

Max( Date) as MaxDate

Resident FACT;

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

Let vMaxDate = Date( $(vMaxDateNum));

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

LET vPeriod=$(vMaxDate)-$(vMonthStart);

I get another  error "script line error LET vPeriod=08.12.2014-01.12.2014"

MVP
MVP

Re: variable LET script error

Hi

Let evaluates the statement on the RHS before assigning it to the variable. Max(Date) is not a legal statement in script mode outside of a LOAD, so this statement is causing an error.

Your error in the second post - you need quotes around the date variables:

LET vPeriod='$(vMaxDate)'-'$(vMonthStart)';


HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable

Re: variable LET script error

Hello,Jonathan! thanks for explanation!!

I made it as you wrote. Now I dont get an error? but it doesnt calculate Period=(

TempTable1:

LOAD

Max( Date) as MaxDate

Resident FACT;

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

Let vMaxDate = Date( $(vMaxDateNum));

TempTabl2:

Load MonthStart(FieldValue('MaxDate', 1)) as MonthStart,

MonthEnd(FieldValue('MaxDate', 1)) as MonthEnd

resident TempTable1;

Let vMonthStartNum = round(Num( Peek( 'MonthStart', 0, 'TempTable2')));

Let vMonthEndNum= round(Num( Peek( 'MonthEnd', 0, 'TempTable2')));

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

LET vDaysMonth='$(vMonthEndNum)'-'$(vMonthStartNum)';

with code like this thats what I see

MVP
MVP

Re: variable LET script error

Hi

You have changed the definition of the two variables to numbers, so you no longer need expansions and quotes. I think you have a trailing space in the Let vPeriod statement that is causing your problem

Simplify these two statements to:

LET vPeriod = vMaxDateNum - vMonthStartNum;

LET vDaysMonth = vMonthEndNum - vMonthStartNum;

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Community Browser