Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Modify data based on duplicate entry

Hi Gurus,

Need help as I am lost on how to do this.

I have a table which has following structure and data:

UniqIDJulianMonthFLAGStatus
101-2420124201AActive
101-2420224202NActive
101-2420324203CClosed
101-2420424204NClosed
101-2420524205NClosed
101-2420624206AActive
102-2420124201AActive
102-2420224202NActive

Business rule is to have only first entry of Flag and ignore all to mark as 'N' for all UniqueIDs. I developed code to generate flag based on first entry using PEEK to compare with previous row. I want to convert all A or C to N after their first instance.

Result set should look like this:

UniqIDJulianMonthFLAGStatus
101-2420124201AActive
101-2420224202NActive
101-2420324203CClosed
101-2420424204NClosed
101-2420524205NClosed
101-2420624206NActive
102-2420124201AActive
102-2420224202NActive

I am quite lost on how to identify one value duplicate and change the value grouping at UniqIDs. Appreciate if anyone can guide. Thanks.

6 Replies
Kushal_Chawda

Data:

LOAD RowNo() as Row,

     UniqID,

     FLAG,

     Status

FROM

[https://community.qlik.com/thread/269304]

(html, codepage is 1252, embedded labels, table is @1);

New:

LOAD *,

     if(UniqID=Previous(UniqID) and FLAG='N' and Peek(NewFlag)=1,Peek(NewFlag)+1,0) as NewFlag2;

LOAD UniqID,

     Row,

     FLAG,

     if(UniqID=Previous(UniqID) and FLAG='N',1,0) as NewFlag,

     Status

Resident Data

Order by Row;

DROP Table Data;

Final:

NoConcatenate

LOAD *,

     if(UniqID=Previous(UniqID) and FLAG<>'N' and Previous(NewFlag2)=2,'N',FLAG) as NEWFLAG

Resident New;

DROP Table New;

drop Fields NewFlag2,NewFlag;

Kushal_Chawda

You need to order your Data properly, I think you need to oder your data by Unique iD & Date, here you don't have Date so I followed the actual load

Not applicable
Author

Hi Kushal,

Thanks. I tried the code but it has not removed any rows and generated 4 duplicates rows for each row with flag value N. To generate more uniqueness, I generated new UniqueIDs which is a combination of UniqueID+JulianMonth. This create unique ID for each row. Now UniqueID looks like this:

Previous UniqueID: 100, 100, 100, 101, 102 etc..

Now new UniqueID: 100-2402, 100-2403, 100-2404,101-2403 etc..

I also have Julian month for every row now which is not duplicated i.e. one row belong to one julian month only.

Please could you guide.

Kushal_Chawda

Can you share sample data?

Not applicable
Author

Hi Kushal,

I updated the data in main post. Result-set of your code is same data with repeat of all data 4 times where FLAG = 'N'

Not applicable
Author

Hi Guru's

Please help. I am lost