Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Load Record with Max value only

From the following script, i only want to load the record with the max setupdate


I am really struggling making others' answers work for my application.It's a simple thought...so i'm sure someone has a simple answer

Temp:

LOAD * INLINE [

    Company, Contact, SetupDate, Source,   RecNo

    1,  David,   41607,    AMP,       123

    1,  Tom,     41609,    Label,     456

    1,  Mary,    41610,    Internet,  789

    2,  Joe,    40600,    Referral,   1011

    3,  Tom,    41666,    Internet,   1213

    3,  Peter,   40600,    AMP,       1415

];

I want to return all fields, Company, Contact, Source, Recno ...but only the one with the max date. (By company)

Final:

LOAD * INLINE [

    Company, Contact, SetupDate, Source,   RecNo

    1,  Mary,    41610,    Internet,  789

    2,  Joe,    40600,    Referral,   1011

    3,  Tom,    41666,    Internet,   1213

];

so i should return 3 records...the 3rd, 4th, and 5th records based on the setupdate by company. I want to do this in the script, please help

-David

Tags (3)
1 Solution

Accepted Solutions
Employee
Employee

Re: Load Record with Max value only

tmp:

LOAD * INLINE [

    Company, Contact, SetupDate, Source,   RecNo

    1,  David,   41607,    AMP,       123

    1,  Tom,     41609,    Label,     456

    1,  Mary,    41610,    Internet,  789

    2,  Joe,    40600,    Referral,   1011

    3,  Tom,    41666,    Internet,   1213

    3,  Peter,   40600,    AMP,       1415

];

filter:

inner keep load

    Company,

    max(SetupDate) as SetupDate

resident tmp

group by Company;

drop table filter;

11 Replies
venkatg6759
Contributor III

Re: Load Record with Max value only

Left Join (Temp)

Load

Company,

max(Timestamp(SetupDate),'MM/DD/YYYY hh:mm:ss') as MaxDate

Resident Temp Group by Company;

Final:

Noconcatenate

Load * Resident Temp Where SetupDate=MaxDate;

Drop Table Temp;

venkatg6759
Contributor III

Re: Load Record with Max value only

Check the attachment .

Thanks,

Venkata

Not applicable

Re: Load Record with Max value only

Thank you for the quick response...My reload is getting hung up on doing it this way...is there another way to attack this problem?

Not applicable

Re: Load Record with Max value only

Thank you! I'm unfortunately on personal edition

venkatg6759
Contributor III

Re: Load Record with Max value only

Copy the code

Temp:

LOAD * INLINE [

    Company, Contact, SetupDate, Source,   RecNo

    1,  David,   41607,    AMP,       123

    1,  Tom,     41609,    Label,     456

    1,  Mary,    41610,    Internet,  789

    2,  Joe,    40600,    Referral,   1011

    3,  Tom,    41666,    Internet,   1213

    3,  Peter,   40600,    AMP,       1415

];

Left Join (Temp)

Load

Company,

max(Timestamp(SetupDate),'MM/DD/YYYY hh:mm:ss') as MaxDate

Resident Temp Group by Company;

Final:

Noconcatenate

Load * Resident Temp Where SetupDate=MaxDate;

Drop Table Temp;

Not applicable

Re: Load Record with Max value only

This is just a small example, that i'm trying to port over into a larger process...is there another way to get after this same solution?

Thank you sincerely !!

venkatg6759
Contributor III

Re: Load Record with Max value only

Post your qvw and let us know know what you are trying to accomplish.

Re: Load Record with Max value only

I would approach it like this:

INNER JOIN (Temp)

LOAD

  max(SetupDate) as SetupDate,

  Company

RESIDENT Temp

GROUP BY Company

;

-Rob

Not applicable

Re: Load Record with Max value only

Hi David,

you can fill first a refenrece table ony with max dates by company you want to keep

LOAD

Company,          as Ref_Company

max(contact)      as Ref_date

from ... group by company

Then load your full table

LOAD * FROM .... WHERE EXISTS(Ref_Company & Ref_Date, Company & Contatc)

best regards

chris

Community Browser