Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
ahbzshk07
Contributor III
Contributor III

Peek function 3rd parameter issue

Hello Everyone!


Can't we use variable in Peek() function at the place where we write table name (3rd parameter)?


If yes, then what is the problem in following code (please refer to the screenshot below)?

The purpose is to get (26/01/2016 - 25/02/2016) for fieldname '1' (as per total number of days in January)

(26/02/2016 - 25/03/2016) for fieldname '2' (for feb) and so on.


As far as I know, the table name must be written in single quotes.


When I replace the darkened part in screenshot with


if($(i)=2,'FisTab',if($(i)=3,'FisTab-1',if($(i)=4,'FisTab-2','further if conditions'))) ,


I get the desired output. But then the if condition becomes too lengthy to be likely used.


I am attaching the .qvw file.

Regards.

1 Solution

Accepted Solutions
sunny_talwar

Try this:

[FisTab-1]:

LOAD Date(MakeDate(2016,01,25)+RecNo(),'DD/MM/YYYY') as 1

AutoGenerate(Day(MonthEnd(MakeDate(Year(Today()),1,1))));

Let tNum=1;

LET tName = 'FisTab-'&$(tNum);

LET tName1 = 'FisTab-'&($(tNum)+1);

FOR i=2 to 12

[$(tName1)]:

LOAD Date(MakeDate(Year(Today()), $(i), Day(Peek($(i)-1,-1,'$(tName)'))) + RecNo(),'DD/MM/YYYY') as $(i)

AutoGenerate(Day(MonthEnd(MakeDate(Year(Today()),$(i),1))));

tNum=$(i)-1;

LET tName = 'FisTab-'&($(tNum)+1);

LET tName1 = 'FisTab-'&($(tNum)+2);

NEXT i

View solution in original post

4 Replies
sunny_talwar

Try this:

[FisTab-1]:

LOAD Date(MakeDate(2016,01,25)+RecNo(),'DD/MM/YYYY') as 1

AutoGenerate(Day(MonthEnd(MakeDate(Year(Today()),1,1))));

Let tNum=1;

LET tName = 'FisTab-'&$(tNum);

LET tName1 = 'FisTab-'&($(tNum)+1);

FOR i=2 to 12

[$(tName1)]:

LOAD Date(MakeDate(Year(Today()), $(i), Day(Peek($(i)-1,-1,'$(tName)'))) + RecNo(),'DD/MM/YYYY') as $(i)

AutoGenerate(Day(MonthEnd(MakeDate(Year(Today()),$(i),1))));

tNum=$(i)-1;

LET tName = 'FisTab-'&($(tNum)+1);

LET tName1 = 'FisTab-'&($(tNum)+2);

NEXT i

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

As Sunny has pointed out, the tablename parameter cannot be a calculated parameter. It must be a literal string. So doing the calculation into a variable as Sunny suggested should work.

-Rob

ahbzshk07
Contributor III
Contributor III
Author

Thanks Sunny... putting the third parameter variable in single quotes in my solution is working too...

But I got to learn about dynamically naming tables with alphanumeric values through your solution... I did not know that

Thanks a lot buddy...

Regards...

ahbzshk07
Contributor III
Contributor III
Author

Yeah, I was unaware of that... it being variable, I did not think of putting it in quotes...

Thanks buddy...

Regards...