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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Add alphabets as a suffix

Hi,

I want to add alphabets as a suffix ,only if the string value is appearing more than once in a field.

For Ex: the data is as shown in the below table.

Docidprice
15025
15030
15045
2530
20010
20012

I want the results as shown below. Suffix should be added only if the doc id is appearing more than once and count of doc id will not be same always.

Docidprice
150-a25
150-b30
150-c45
2530
200-a10
200-b12

Thanks in advance.

Regards,

Chaithra

1 Solution

Accepted Solutions
jagan
Partner - Champion III
Partner - Champion III

Hi,

Try like this

Temp:

LOAD *

INLINE [

Docid, price

150, 25

150, 30

150, 45

25, 30

200, 10

200, 12];

LEFT JOIN (Temp)

LOAD

Docid,

Count(Docid) AS Count

RESIDENT Temp

Group By Docid;

Data:

LOAD

*,

If(Not isNull(AsciiValue), Docid & '-' & Chr(AsciiValue), Docid) AS New_Docid;

LOAD

Docid,

price,

If(Peek(Docid) <> Docid AND Count > 1, 65, If(Peek(Docid) = Docid, Peek(AsciiValue) + 1, Null())) AS AsciiValue

RESIDENT Temp

ORDER BY Docid, price;

DROP TABLE Temp;

Regards,

Jagan.

View solution in original post

7 Replies
jagan
Partner - Champion III
Partner - Champion III

Hi,

Try like this

Temp:

LOAD *

INLINE [

Docid, price

150, 25

150, 30

150, 45

25, 30

200, 10

200, 12];

LEFT JOIN (Temp)

LOAD

Docid,

Count(Docid) AS Count

RESIDENT Temp

Group By Docid;

Data:

LOAD

*,

If(Not isNull(AsciiValue), Docid & '-' & Chr(AsciiValue), Docid) AS New_Docid;

LOAD

Docid,

price,

If(Peek(Docid) <> Docid AND Count > 1, 65, If(Peek(Docid) = Docid, Peek(AsciiValue) + 1, Null())) AS AsciiValue

RESIDENT Temp

ORDER BY Docid, price;

DROP TABLE Temp;

Regards,

Jagan.

Not applicable
Author

Hi Jagan,

Thanks for your response.

I am getting some error while joining the table.

Regards,

Chaithra

jagan
Partner - Champion III
Partner - Champion III

It is working correctly for me.  can u attach the script you are using.

anbu1984
Master III
Master III

T1:
Load *,AutoNumber(Docid+price,Docid) As RowNo Inline [
Docid,price
150,25
150,30
150,45
25,30
200,10
200,12 ]
;

T2:
Load Docid & If(Docid = Previous(Docid),'-' &Chr(96+RowNo),If(RowNo > 1,'-'&Chr(96+RowNo),'')),price Resident T1 Order By Docid,RowNo desc;

Drop Table T1;

Not applicable
Author

Thanks for the help, its working fine.

Not applicable
Author

Thank you. Even this method is giving the correct output.

anbu1984
Master III
Master III

My ans isn't helpful