Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Maxstring and Distinct

I have a table with 4 columns, I need to know how to do something in the load script like the following.

MaxString(SalePrimaryKey), Distinct(Employee), Sales, Count. Does anyone have any ideas?

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

HI,

Try Inner Join using the simple script below

Table:

LOAD * Inline [

SalePrimaryKey, EmployeeID, Sales, Count

1, 546, 500, 7

2, 128, 1000, 9

3, 546, 1250, 5

4, 896, 50, 1

5, 452, 1583, 84

6, 546, 1540, 4

7, 236, 1531, 2

];

INNER JOIN(Table)

LOAD EmployeeID,

Max(SalePrimaryKey)

Resident Table

Group By EmployeeID;


Hope this helps you.


Regards,

Jagan.

View solution in original post

8 Replies
cesaraccardi
Specialist
Specialist

Try this:

LOAD

     Employee,

     Maxstring(SalePrimaryKey), as SalePrimaryKey,

     FirstSortedValue(Sales) as Sales,

     FirstSortedValue(Count) as Count

GROUP BY

     Employee;

sunny_talwar

Do you mean FirstValue instead of FirstSortedValue? FirstSortedValue takes two inputs:

LOAD

     Employee,

     Maxstring(SalePrimaryKey), as SalePrimaryKey,

     FirstValue(Sales) as Sales,

     FirstValue(Count) as Count

GROUP BY

     Employee

But somehow the above doesn't seem right as we are not sorting the table. Zeth would you be able to share some sample data with expected output?

cesaraccardi
Specialist
Specialist

Yes, thats right thanks. I meant FirstValue(), alternatively those fields could be listed on the group by clause:

LOAD

     Employee,

     Maxstring(SalePrimaryKey), as SalePrimaryKey,

     Sales,

     Count

GROUP BY

     Employee, Sales, Count;

Not applicable
Author

This is the initial data, you can see employeeID 546 is duplicated. I want to return the Employee ID with the greatest SalePrimary Key.

SalePrimaryKeyEmployeeIDSalesCount
15465007
212810009
354612505
4896501
5452158384
654615404
72361531

2

So it would return the following. 

SalePrimaryKeyEmployeeIDSalesCount
212810009
4896501
5452158384
654615404
723615312
sunny_talwar

May be this:

Table:

LOAD * Inline [

SalePrimaryKey, EmployeeID, Sales, Count

1, 546, 500, 7

2, 128, 1000, 9

3, 546, 1250, 5

4, 896, 50, 1

5, 452, 1583, 84

6, 546, 1540, 4

7, 236, 1531, 2

];

FinalTable:

NoConcatenate

LOAD EmployeeID,

  FirstSortedValue(SalePrimaryKey, -SalePrimaryKey) as SalePrimaryKey,

  FirstSortedValue(Sales, -SalePrimaryKey) as Sales,

  FirstSortedValue(Count, -SalePrimaryKey) as Count

Resident Table

Group By EmployeeID;

DROP Table Table;


Capture.PNG

Not applicable
Author

This keeps returning a syntax error, missing/misplaced FROM:

sunny_talwar

I won't be able to see the same error, because I am using an inline load. Would you be able to share your script and the exact error that you are seeing???

Best,

Sunny

jagan
Luminary Alumni
Luminary Alumni

HI,

Try Inner Join using the simple script below

Table:

LOAD * Inline [

SalePrimaryKey, EmployeeID, Sales, Count

1, 546, 500, 7

2, 128, 1000, 9

3, 546, 1250, 5

4, 896, 50, 1

5, 452, 1583, 84

6, 546, 1540, 4

7, 236, 1531, 2

];

INNER JOIN(Table)

LOAD EmployeeID,

Max(SalePrimaryKey)

Resident Table

Group By EmployeeID;


Hope this helps you.


Regards,

Jagan.