Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
pra_kale
Creator III
Creator III

To Find Max value in a One Column

Hi,

Below given is the sample data in which for one Policy there are Two or Three Premium values. I want a maximum value for that policy only through script so that will become my base data for further calculation.

Please suggest how I can achieve this in script

 

Policy_noPremiumName
123456785000Jon
10002345100000Joseph
1234568840000Kern
1234527860000Ritu
123456783000Jon
10002345200000Joseph
1234568860000Kern
1234527840000Ritu
12345688100000Kern
12345278800000Ritu
567894525000Jeevan
369874123980Kiran

Final Out_put should be like this..

   

Policy_noPremiumName
123456785000Jon
10002345200000Joseph
12345688100000Kern
12345278800000Ritu
567894525000Jeevan
369874123980Kiran

 


Thanks in advance..

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

Here is how you can achieve it in a load script:

B:

LOAD

  Policy_no,

  Max(Premium),

  FirstSortedValue(Name,Premium)

RESIDENT

  A

GROUP BY

  Policy_no;

View solution in original post

11 Replies
Not applicable

select max(column_name)

petter
Partner - Champion III
Partner - Champion III

Here is how you can achieve it in a load script:

B:

LOAD

  Policy_no,

  Max(Premium),

  FirstSortedValue(Name,Premium)

RESIDENT

  A

GROUP BY

  Policy_no;

petter
Partner - Champion III
Partner - Champion III

and if you don't need the A table at all for other purposes you could make this into a preceding load like this:

A:

LOAD

  Policy_no,

  Max(Premium),

  FirstSortedValue(Name,Premium)

GROUP BY

  Policy_no;

LOAD Policy_no,

     Premium,

     Name

FROM

  [sample_Max value.xlsx]

  (ooxml, embedded labels, table is Sheet1);

petter
Partner - Champion III
Partner - Champion III

or directly from the Excel file without preceding load:

A:

LOAD

  Policy_no,

  Max(Premium),

  FirstSortedValue(Name,Premium)

FROM

  [sample_Max value.xlsx]

  (ooxml, embedded labels, table is Sheet1)

GROUP BY

  Policy_no;

pra_kale
Creator III
Creator III
Author

That's Great...Both the solutions are Helpful..

But, currently for further use I will go with Second solution..

Just One question..If I have more than 3 or 4 columns then I have to include in a script like this. Please correct me if I am wrong.. or any other way to this.

FirstSortedValue(Name,Premium,Column 3, Column 4, Column 5, Column 6,...etc).

Kushal_Chawda

In this case you can do like this

FirstSortedValue(Column 3,Premium) as Column 3,

FirstSortedValue(Column 4,Premium) as Column 4

FirstSortedValue(Column 5,Premium) as Column 5

and so on

petter
Partner - Champion III
Partner - Champion III

Adding a third parameter will only pick the n'th value so a number 2 for the third parameter will not select the first sorted value but the second sorted value. So you have to go for just using two parameters like: FirstSortedValue(Column N, Premium) AS ColN for each additional column.

pra_kale
Creator III
Creator III
Author

Thanks for Your Help...That's Great.

pra_kale
Creator III
Creator III
Author

Too Good..Great..Thanks for Your Help.