Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to store the values in a Table into a variable

TagName

Fill A Time

Fill B Time

Fill C Time

Tag A

06:00

Tag A

06:05

Tag A

06:09

Tag B

06:02

Tag B

06:03

Tag B

06:05

Tag B

06:06

Tag C

06:03

Tag C

06:05

Tag C

06:07

can anyone, please help me,  is there a way to get the last value for each field in the table..

To be clear, in the above situation, for each tag I will have lot of rows, but I am interested in the last row of each Tagname. Is there a way to get a last record for each value.

usually, we use Peak function to get the Filed value in a Table,we have to give the row number for accessing the value..

In my case, each tag will have more than one value and i will have no idea, which row number i should give in the peek function.

Is there a way to do it using peek function or do we have any other function..

please help me with this

Thank you

cleveranjoshallquist_nate

32 Replies
MK_QSL
MVP
MVP

What is the format of [Fill A TIme]. Can you give one example here?

Not applicable
Author

NoConcatenate

  GetPOTime:

  SELECT TagName as TagsPOTime,

  DateTime as POTime

  FROM

  History

WHERE

  TagName IN$(vTagForPO)

  AND DateTime >= '$(vProdStartTime)'

  AND DateTime <= '$(vThisExecTime)'

  NoConcatenate

  FactGetPOChangeTime:

  LOAD

  TagsForPOTime,

  if(TagsForPOTime='Fill A',POTime,0) as Fill A Time,

  if(TagsForPOTime='Fill B',POTime,0) as Fill B Time,

  if(TagsForPOTime='Fill C',POTime,0) as Fill C Time

  Resident GetPOChangeTime;

 

  LET vFillATime=Max([Fill A Time]);

  LET vFillBTime=Max([Fill B Time]);

  LET vFillCPOTime=Timestamp(Max(Fill C TIme),'YYYY-MM-DD hh:mm:ss');

when i use the this Timestamp(Max(Fill C TIme),'YYYY-MM-DD hh:mm:ss'); expression in a text object, I am getting the exact value

//LET vFillCPOTime1=Time(Max(Time#([BoschCPOTIme],' YYYY-MM-DD hh:mm:ss')),'YYYY-MM-DD hh:mm:ss');

Not applicable
Author

Hi Manuel

i used, Resident Two times. and I am not getting errors now.

but, could you please explain about the for loop.. i read about the replace function.. so here we are not replacing anything, but we used replace function..

I have three TagNames right,, which TagName should i keep in place of TagName2

     LET vNameVar = Replace(Peek('TagName2',$(i),'Max'),' ',''); 

Thank you

Not applicable
Author

Hi Avinash,, can you give me your mail id please??

Anonymous
Not applicable
Author

Hi Ganesh,

I use replace function because you can have some blankspaces on your TagName, and a Variable name cannot have blankspaces. I replace a blankspace with an empty string.

I have used TagName2 because I wanna show you that you can use whenever you want the same field, provided that the field is in the GROUP BY.


With the loop, I get each tagname, give this name to a variable, and get the max value to this variable. If you have 20 tagnames, you will create 20 variables.

Regards!

Not applicable
Author

Actually.. Its tricky for me..

So, which tagname should i keep in place of Tagname2   and My i get the time in

Timestamp "YYYY-MM-DD hh:mm:ss"..

so can i use,

LET v$(vNameVar) = Time(Peek('MaxValue',$(i),'Max'),'YYYY-MM-DD hh:mm:ss');

in that variable expression??

Thank you

Anonymous
Not applicable
Author

You can use TagName in place of TagName.

If your TimeStamp is recognized by QlikView, you can use your format, if your timestamp is not recogniced (you get your timestamp as a string), use this:

LET v$(vNameVar) = Time(Time#(Peek('MaxValue',$(i),'Max'),'YYYY-MM-DD hh:mm:ss'),'YYYY-MM-DD hh:mm:ss');


Regards!!

Not applicable
Author

Hi Manuel

i am getting same script line error for at for loop

sfchov.PNG

i think, it is because of noofrows function, do we have  to give the TableName in our scenario.

Thank you

Anonymous
Not applicable
Author

Hi Ganesh, 'Max' is the name of the table, could you share the log of execution please?

Regards!

Not applicable
Author

could you please give me your email id