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

Loading only max values

Hi guys,

I am loading an SQL table with values for Date, Type and Amount. Sometimes I have multiple values for the same Date and Type, but with different amounts. For each Date and Type combo, I'm looking to load only those records that have the Max amount.

Date     Type     Amount

x           a          10

y           a          12

z           a          8

z           a          15

So in this table I only want z, a, 15 to load. Any way I can simply do this by altering my Load script maybe?

1 Solution

Accepted Solutions
Gysbert_Wassenaar

MyTable:

SQL SELECT Date, Type, Amount

FROM ...mytable...;

right join (MyTable)

LOAD Type, max(Amount) as Amount;

RESIDENT MyTable

GROUP BY Type;


talk is cheap, supply exceeds demand

View solution in original post

5 Replies
jpapador
Partner - Specialist
Partner - Specialist

LOAD

Date,

Type,

Max(Amount) as MaxAmount

Resident Temp1

Group By Date, Type;

its_anandrjs

Hi,

You can try this also

Raw:
LOAD * INLINE [
Date, Type, Amount
x, a, 10
y, a, 12
z, a, 8
z, a, 15
]
;
 
LOAD
Max(Amount) as Amount
Resident Raw;

Left Join
LOAD * Resident Raw;

DROP Table Raw;


Regards

Anand

Gysbert_Wassenaar

MyTable:

SQL SELECT Date, Type, Amount

FROM ...mytable...;

right join (MyTable)

LOAD Type, max(Amount) as Amount;

RESIDENT MyTable

GROUP BY Type;


talk is cheap, supply exceeds demand
anbu1984
Master III
Master III

LOAD

Date,

Type,

Firstsortedvalue(Amount,-Amount) as MaxAmount

Group By Date, Type;

Sql Select Date,Type,Amount From Table;

Or

LOAD

Date,

Type,

Max(Amount) as MaxAmount

Group By Date, Type;

Sql Select Date,Type,Amount From Table;

Not applicable
Author

Thanks! I couldn't get it to work at first but when I took the max of a new variable, date and type combined, the right join worked like a charm