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

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Find Max and Insert

I have Table1 with Employee's Sales data. Need to find the Employee with highest Sales by Client ID, Category and if Year is 2015, find Employee with highest Sales by Client ID and Category in 2015 other wise find in 2014 and insert that Employee ID in Table2 for that Client ID and Category for rows where Insert is 'Y'.

For example, from Table1, 2.3, 2.5 and 1.7 are inserted into Table2.

Attached is the Excel with same entries. Need to write this in the load script.

Will really appreciate any help.

Table1:

Client IDClient NameEmp NameEmployee ID$ Sales (in millions)CategoryYear
1ClientAJohn emp11.54loans2015
1ClientAPeteremp22.3loans2015
1ClientAAlanemp34loans2014
1ClientAPeteremp22.5investment2014
1ClientAAlanemp32.3investment2014
3ClientCJohn emp11.7research2015
3ClientCJohn emp11.9research2014
3ClientCAlanemp31.8research2014

Table2:

Client IDClient NameProduct TypeInsertRegionEmpoyee ID
1ClientAloansYEurope2.3
1ClientAloansNEurope
1ClientAinvestmentYAmerica2.5
1ClientAinvestmentYEurope2.5
1ClientAinvestmentYAsia2.5
3ClientCresearchNAmerica
3ClientCresearchNAsia
3ClientCresearchYEurope1.7
1 Solution

Accepted Solutions
anbu1984
Master III
Master III

Table1:

LOAD [Client ID],

     [Client Name],

     [Emp Name],

     [Employee ID],

     [$ Sales (in millions)],

     Category,

     Year

FROM

[EmployeeSalesInsert.xlsx]

(ooxml, embedded labels, table is Table1);

Temp:

NoConcatenate

Load ClntId,ProdType,Max(Yr) As Yr,FirstSortedValue(EmpId,-Yr) As EmpId Group By ClntId,ProdType;

Load [Client ID] As ClntId,Category As ProdType, Year As Yr, Max([$ Sales (in millions)]) As EmpId Resident Table1 Group By [Client ID],Category, Year;

Join(Temp)

Load [Client ID] As ClntId,

     [Client Name],

     Category As ProdType,

     [$ Sales (in millions)] As EmpId

Resident Table1;

Table2:

Load *, If(IsNull(Yr),'N','Y') As Insert,If(IsNull(Yr) <> -1,EmpId) As EmployeeId Resident Temp;

Drop Table Temp;

View solution in original post

2 Replies
anbu1984
Master III
Master III

Table1:

LOAD [Client ID],

     [Client Name],

     [Emp Name],

     [Employee ID],

     [$ Sales (in millions)],

     Category,

     Year

FROM

[EmployeeSalesInsert.xlsx]

(ooxml, embedded labels, table is Table1);

Temp:

NoConcatenate

Load ClntId,ProdType,Max(Yr) As Yr,FirstSortedValue(EmpId,-Yr) As EmpId Group By ClntId,ProdType;

Load [Client ID] As ClntId,Category As ProdType, Year As Yr, Max([$ Sales (in millions)]) As EmpId Resident Table1 Group By [Client ID],Category, Year;

Join(Temp)

Load [Client ID] As ClntId,

     [Client Name],

     Category As ProdType,

     [$ Sales (in millions)] As EmpId

Resident Table1;

Table2:

Load *, If(IsNull(Yr),'N','Y') As Insert,If(IsNull(Yr) <> -1,EmpId) As EmployeeId Resident Temp;

Drop Table Temp;

Anonymous
Not applicable
Author

Thank you.