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: 
Not applicable

how to use first function in qlikview?

hi guys,

I created table box in qlikview.I want to select first 4 employees in that table box  so that I use First () function in script but the first () function did not work .I do not know how to use FIRST() function in qlikview.Please tell me out  how to useFIRST() function in qlikview.

I attached snipping file below this box.

Regards:

madhu

13 Replies
maxgro
MVP
MVP

to only load 4 rows

table:

first 4 LOAD

     *

from sometable;

Not applicable
Author

Thanks grossi .I wrote first() function in my script like this.

First (4) Load * from Employees;

Not applicable
Author

but It is not work.

Joseph_Musekura
Support
Support

Hi

you don't need () when using first

See attached: click table viewer, each table has 4 rows only

Regards

Joseph_Musekura
Support
Support


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 one-dimensional 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 one-dimensional 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.
its_anandrjs

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

(ooxml, embedded labels, Table is Sheetl);

NoConcatenate

First 4

LOAD *

Resident Employees;

DROP Table Employees;

maxgro
MVP
MVP

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.)

rbecher
MVP
MVP

..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;

Astrato.io Head of R&D
maxgro
MVP
MVP

Employees:

first 4

LOAD Empkey,

  Employname,

  salary

FROM

(ooxml, embedded labels, Table is Sheetl);