
Re: how to use first function in qlikview?
Massimo Grossi May 4, 2014 1:46 PM (in response to Madhu Reddy)to only load 4 rows
table:
first 4 LOAD
*
from sometable;

Re: how to use first function in qlikview?
Madhu Reddy May 4, 2014 2:10 PM (in response to Massimo Grossi )Thanks grossi .I wrote first() function in my script like this.
First (4) Load * from Employees;

Re: how to use first function in qlikview?
Madhu Reddy May 4, 2014 2:11 PM (in response to Massimo Grossi )but It is not work.

Re: how to use first function in qlikview?
Massimo Grossi May 4, 2014 2:38 PM (in response to Madhu Reddy)Why doesn't work? First works with and without ()
I think you want some different thing; first 4 employees by salary? try to explain, thanks.
First
The First prefix to a Load or Select (SQL) statement is used for loading just a set maximum number of records from the data source, regardless of its length.
The syntax is:
first n ( loadstatement  selectstatement )
where:
n is an arbitrary expression which evaluates to an integer indicating the maximum number of records to be read.
Examples:
First 10 LOAD * FROM abc.csv;
First (1) SQL SELECT * FROM Orders; (Note: The parenthesis is allowed but not required.)

Re: how to use first function in qlikview?
Madhu Reddy May 5, 2014 11:01 AM (in response to Massimo Grossi )Thank you very much Grossi it works.


Re: how to use first function in qlikview?
Ralf Becher May 4, 2014 2:45 PM (in response to Madhu Reddy)..because Employees is an already loaded table. You need to load from resident with a NoConcatenate prefix (to prevent the load in the same table Emplyees):
NewTable:
NoConcatenate First 4 Load * Resident Employees;
// Then you need to drop the original table or you will get a synthetic key on all fields:
Drop Table Employees;

Re: how to use first function in qlikview?
Massimo Grossi May 4, 2014 3:41 PM (in response to Ralf Becher )Employees:
first 4
LOAD Empkey,
Employname,
salary
FROM
[d:\madhu\Data\Salary.xlsx]
(ooxml, embedded labels, Table is Sheetl);

Re: how to use first function in qlikview?
Madhu Reddy May 5, 2014 11:01 AM (in response to Ralf Becher )thank you Becher it works




Re: how to use first function in qlikview?
Joseph Musekura May 4, 2014 2:17 PM (in response to Madhu Reddy)Hi
you don't need () when using first
See attached: click table viewer, each table has 4 rows only
Regards

firstUseTest.qvw 154.8 K

Re: how to use first function in qlikview?
Madhu Reddy May 5, 2014 11:02 AM (in response to Joseph Musekura )Thank you joseph


Re: how to use first function in qlikview?
Joseph Musekura May 4, 2014 2:23 PM (in response to Madhu Reddy)
Hi,There is another context when using First() or Last(). See below from QlikView reference manual :
first([ total ] expression [ , offset [,n ]])
Returns the value of expression evaluated with a pivot table's dimension values as they appear in the first column of the current row segment in the pivot table. This function returns NULL in all chart types except pivot tables.
If the table is onedimensional or if the expression is preceded by the total qualifier, the current row segment is always equal to the entire row.
If the pivot table has multiple horizontal dimensions, the current row segment will include only columns with the same values as the current column in all dimension rows except for the row showing the last horizontal dimension of the inter field sort order. The inter field sort order for horizontal dimensions in pivot tables is defined simply by the order of the dimensions from top to bottom.
Specifying an offset greater than 1 lets you move the evaluation of expression to columns further to the right of the first column. A negative offset number will actually make the first function equivalent to a last function with the corresponding positive offset number. Recursive calls will return NULL.
By specifying a third parameter n greater than 1, the function will return not one but a range of n values, one for each of the first n columns of the current row segment. In this form, the function can be used as an argument to
any of the special Chart
Range Functions.Examples:
first( sum( Sales ))
first( sum( Sales ), 2 )
first( total sum( Sales )
rangeavg (first(sum(x),1,5)) returns an average of the results of the sum(x)
function evaluated on the five leftmost columns of the current row segment.last([ total ] expression [ , offset [,n ]])
Returns the value of expression evaluated with a pivot table's dimension values as they appear in the last column of the current row segment in the pivot table. This function returns NULL in all chart types except pivot tables.
If the table is onedimensional or if the expression is preceded by the total qualifier, the current row segment is always equal to the entire row.
If the pivot table has multiple horizontal dimensions, the current row segment will include only columns with the same values as the current column in all dimension rows except for the row showing the last horizontal dimension of the inter field sort order. The inter field sort order for horizontal dimensions in pivot tables is defined simply by the order of the dimensions from top to bottom.
Specifying an offset greater than 1 lets you move the evaluation of expression to columns further to the
left of the last column. A negative offset number will actually make the last function equivalent to a first function with the corresponding positive offset number. Recursive calls will return NULL.By specifying a third parameter n greater than 1, the function will return not one but a range of n
values, one for each of the last n columns of the current row segment. In this form, the function can be used as an argument to any of the special Chart
Range Functions.Examples:
last( sum( Sales ))
last( sum( Sales ), 2 )
last( total sum( Sales )
rangeavg (last(sum(x),1,5)) returns an average of the results of the sum(x)
function evaluated on the five rightmost columns of the current row segment. 
Re: how to use first function in qlikview?
Anand Chouhan May 4, 2014 2:50 PM (in response to Madhu Reddy)You can write some thing like below script for First 4 and load another resident table for this also you can do this with existing but you can try below script.
Employees:
LOAD Empkey,
Employname,
salary
FROM
[d:\madhu\Data\Salary.xlsx]
(ooxml, embedded labels, Table is Sheetl);
NoConcatenate
First 4
LOAD *
Resident Employees;
DROP Table Employees;

Re: how to use first function in qlikview?
Marco Wedel May 4, 2014 6:56 PM (in response to Madhu Reddy)Hi madhu,
if you just want to show the first four employees in a table then you might also use a straight table instead of a table box and limit the dimensions like this:
regards
Marco

QlikCommunity_Thread_117124.qvw 148.5 K
