Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
entsh
Contributor II
Contributor II

group by FirstSortedValue

hi

in edit script i used this code

select

code,name,number from....

the result is:

codenamenumber
5teh500
6teh600
7teh300
4ker100
5ker200
6ker400
8un500

 

but i want this

for each name just show the maximum code:(code for edit script)

codenamenumber
7teh300
6ker400
8un500

 

would u please help me?

3 Solutions

Accepted Solutions
Taoufiq_Zarra

@entsh  Maye be :

Data:
LOAD * INLINE [
    code, name, number
    5, teh, 500
    6, teh, 600
    7, teh, 300
    4, ker, 100
    5, ker, 200
    6, ker, 400
    8, un, 500
];

output:
noconcatenate

load Max(code) as code,name,FirstSortedValue(number,-code) as number resident Data group by name;

drop table Data;

 

output:

Taoufiq_Zarra_0-1631967645048.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

AshutoshBhumkar
Partner - Specialist
Partner - Specialist

Hello,

Another way is to create flag. Though the way @Taoufiq_Zarra has shown is absolutely correct. 🙂

Table:
Load code, name,number,code&'-'&name as codeName;
Load * Inline [
code,name,number
5,teh,500
6,teh,600
7,teh,300
4,ker,100
5,ker,200
6,ker,400
8,un,500
];

NoConcatenate
Table2:
Load
Max(code)&'-'&name as codeName,
'1' as Flag
resident Table group by name;

AshutoshBhumkar_0-1631976981204.png

Thanks,

Ashutosh

View solution in original post

MarcoWedel

Hi,

another solution might be to purge unnecessary lines with a right join like this:

If your data is loaded in table1, then

Right Join (table1)
LOAD name,
     Max(code) as code
Resident table1
Group By name;

 

 

hope this helps
regards
Marco

View solution in original post

3 Replies
Taoufiq_Zarra

@entsh  Maye be :

Data:
LOAD * INLINE [
    code, name, number
    5, teh, 500
    6, teh, 600
    7, teh, 300
    4, ker, 100
    5, ker, 200
    6, ker, 400
    8, un, 500
];

output:
noconcatenate

load Max(code) as code,name,FirstSortedValue(number,-code) as number resident Data group by name;

drop table Data;

 

output:

Taoufiq_Zarra_0-1631967645048.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
AshutoshBhumkar
Partner - Specialist
Partner - Specialist

Hello,

Another way is to create flag. Though the way @Taoufiq_Zarra has shown is absolutely correct. 🙂

Table:
Load code, name,number,code&'-'&name as codeName;
Load * Inline [
code,name,number
5,teh,500
6,teh,600
7,teh,300
4,ker,100
5,ker,200
6,ker,400
8,un,500
];

NoConcatenate
Table2:
Load
Max(code)&'-'&name as codeName,
'1' as Flag
resident Table group by name;

AshutoshBhumkar_0-1631976981204.png

Thanks,

Ashutosh

MarcoWedel

Hi,

another solution might be to purge unnecessary lines with a right join like this:

If your data is loaded in table1, then

Right Join (table1)
LOAD name,
     Max(code) as code
Resident table1
Group By name;

 

 

hope this helps
regards
Marco