Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
lmenendez_grupo_pinero
Contributor III
Contributor III

find max value of a field

How could I capture the maximum value of a field into a variable in order to use it into a loop

Something like this:

set lastrow=max(RowID);

for  n=1 to lastrow

...

Thanks

 

Labels (1)
1 Solution

Accepted Solutions
chris_djih
Creator III
Creator III

you need to make a teporary table for this:
temp: Load Max(RowID) as max_RowId resident table;
Then you can give this value in your variable with Peek():
let lastrow = Peek('max_RowId',-1);

If you found help, mark the correct answer and give some likes to ALL contributors, that tried to help.

View solution in original post

4 Replies
chris_djih
Creator III
Creator III

you need to make a teporary table for this:
temp: Load Max(RowID) as max_RowId resident table;
Then you can give this value in your variable with Peek():
let lastrow = Peek('max_RowId',-1);

If you found help, mark the correct answer and give some likes to ALL contributors, that tried to help.
maxgro
MVP
MVP

If you want to loop on the rows of Table1 and get for every row the value of Field1


Table1:
LOAD * INLINE [
Field1
1
2
3
10
4
5
];

FOR r=0 TO NoOfRows('Table1')-1
    LET vField1 = PEEK('Field1', $(r), 'Table1');
    TRACE $(r) $(vField1);
NEXT

maxgro
MVP
MVP

IF you want to get the max value of Field1 and loop from 1 to max value of Field1


Table1:
LOAD * INLINE [
Field1
1
2
3
10
4
5
];


TMP:
LOAD MAX(Field1) AS Field1Max RESIDENT Table1;
LET vMax = Peek('Field1Max');

FOR i=1 TO $(vMax)
     TRACE $(i);
NEXT

lmenendez_grupo_pinero
Contributor III
Contributor III
Author

Thank for your usefull and quikly help.