Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
haymarketpaul
Creator III
Creator III

Assign Latest ID To Duplicate Records

QV12 SR4

I am being supplied with a table (directly from SQL Server) like the following which essentially contains duplicated people hence the differing PersonIDs but same email address.

PersonIDEmailEventIDCompanyName
1me@you.com123Company1
2me@you.com321Company2
3me@you.com456Company3
4me@you.com654Company4

I would like to use the latest PersonID for each record so would end up with something like this which i can break down to extract EventIDs etc at a later stage:-

PersonIDEmailEventIDCompanyName
4me@you.com123Company1
4me@you.com321Company2
4me@you.com456Company3
4me@you.com654Company4

I'm thinking i could possibly use PEEK if i order the table correctly but have not had to do something quite like this before and perhaps i am missing a better way to achieve this.  Meanwhile i'll have a play with PEEK and see what happens.

Any help appreciated

Labels (1)
1 Solution

Accepted Solutions
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Peek might work, if you order your data set in Email, PersonID descending order.

Alternatively you could use applymap.

MaxPersonIDMap:

MAPPING LOAD

    Email,

    max(PersonID) as maxPersonID

FROM [Your data source]

GROUP BY Email;

Then simply use

ApplyMap('MaxPersonIDMap', Email, '[Unknown]') as PersonID

View solution in original post

5 Replies
Not applicable

Try this in backend

Table:

Load *Inline [

PersonID, Email, EventID, CompanyName

1, me@you.com, 123, Company1

2, me@you.com, 321, Company2

3, me@you.com, 456, Company3

4, me@you.com, 654, Company4

];

left Join

load Email,

max(PersonID) as Psnid

Resident Table group by Email;

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Peek might work, if you order your data set in Email, PersonID descending order.

Alternatively you could use applymap.

MaxPersonIDMap:

MAPPING LOAD

    Email,

    max(PersonID) as maxPersonID

FROM [Your data source]

GROUP BY Email;

Then simply use

ApplyMap('MaxPersonIDMap', Email, '[Unknown]') as PersonID

Not applicable

Try this in front end

=aggr(max(PersonID),Email)

omkarvamsi
Creator
Creator

Hi Paul

Please try below script

abc:

LOAD * INLINE [

    id, name, company

    1, a, cc

    2, a, cf

    3, a, cg

    4, b, cgg

];

maxidtable:

load max(id) as maxid

Resident abc;

LET vLatest=peek('maxid',0,'maxidtable');

load

$(vLatest) as ID,

name,

company

Resident abc;

drop table abc,maxidtable;

haymarketpaul
Creator III
Creator III
Author

Thanks for replies all

Thirumal - backend solution works nicely - good to know

Marcus - went with ApplyMap as the correct answer as a little bit cleaner as i don't have to Left Join any additional fields