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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Merge two values

Hi,

I need to mege two values which are existing in the same field but in last both names are different.

For example:

MyField: These values are coming in the list box

Current Output:

ABC-CDE

ABC-CDEFG

Required Output:

Required output

ABC-CDE


Both should be merge by using great method. Such as using wildmatch etc.

Note: Some times these values are greater then 7 digit

For Example: Current scenario

XYZ-AB-001

XYZ-AB-001-C1

Requried scenario:

XYZ-AB-001


Therefore, I need a method which run in all the scenarios.

regards,

1 Solution

Accepted Solutions
maxgro
MVP
MVP

maybe changing the b load only, difference with previous script posted is in bold

 

Sales:

LOAD field, value, len(field) as len

FROM Sales.xlsx (ooxml, embedded labels, table is Sheet1);

b:

load

  field,

  len,

  value,

  if(wildmatch(field, peek(fieldgroup) & '*') and len(peek(field))>0, peek(fieldgroup), field) as fieldgroup

Resident Sales

order by field, len;

DROP Table Sales;

c:

load

  fieldgroup as field,

  sum(value) as value

Resident b

group by fieldgroup;

drop table b;

View solution in original post

23 Replies
maxgro
MVP
MVP

see attachment, 0 in match is for rows you must keep

1.png

Anonymous
Not applicable
Author

Hi Massimo,

Please share me script, expression. I have personal edition therefore I'm not able to open the qvd.

regards,

maxgro
MVP
MVP

a:

load *, len(field) as len inline [

field

ABC-CDE

ABC-CDEFG

XYZ-AB-001

XYZ-AB-001-C1

AAABBB

ZZZZZ

ZZZ

ZZZZ

];

b:

load

  field,

  len,

  if(wildmatch(field, peek(field) & '*') and len(peek(field))>0, 1, 0) as match

Resident

  a

order by field, len;

DROP Table a;

Anonymous
Not applicable
Author

Hi Massimo,

The problem is still there, as you showed in your image there is match and length column. This is not required.

Current Scenario:

ABC-CDE

ABC-CDEFG

XYZ-AB-001

XYZ-AB-001-C1

AAABBB

ZZZZZ

ZZZ

ZZZZ

and Desired output required:

ABC-CDE

XYZ-AB-001

AAABBB

ZZZ


Please help me, to solve this problem.


regards,

maxgro
MVP
MVP

I add the match and len column to show the solution, if you don't want the 2 columns add a preceding load, in bold, to filter values with match = 0 and to just keep one column

a:

load *, len(field) as len inline [

field

ABC-CDE

ABC-CDEFG

XYZ-AB-001

XYZ-AB-001-C1

AAABBB

ZZZZZ

ZZZ

ZZZZ

];

b:

load field where match=0;

load

  field,

  len,

  if(wildmatch(field, peek(field) & '*') and len(peek(field))>0, 1, 0) as match

Resident

  a

order by field, len;

DROP Table a;

Anonymous
Not applicable
Author

Dear Massimo,

No effect on the data.

This output is coming

ABC-CDE

ABC-CDEFG

XYZ-AB-001

XYZ-AB-001-C1

AAABBB

ZZZZZ

ZZZ

ZZZZ

instead of required output.

ABC-CDE

XYZ-AB-001

AAABBB

ZZZ

maxgro
MVP
MVP

are you sure?

I reload the script and I got 4 rows

1.png

MarcoWedel

Hi,

another solution might be:

QlikCommunity_Thread_148680_Pic1.JPG

table1:

LOAD * INLINE [

    MyField, fact

    ABC-CDE, 1

    ABC-CDEFG, 2

    XYZ-AB-001, 3

    XYZ-AB-001-C1, 4

    BCD-EFGHI-JKLM-0123, 5

    BCD-EFGHI-JKLM, 6

    BCD-EFGHI, 7

    BCD-EFGHIJKL, 8

    BCD-EFGHI-0123, 9

    CDEF-GHIJ-KLMNO, 10

    CDEF-GHIJ-KLMN, 11

    CDEF-GHI-KLMNO, 12

    DEF-GHIJ-LM, 13

    DEF-GHIJ-KL, 14

    DEF-GHIJ-LK, 15

];

Right Join

LOAD MyField Where CountMyField=1;

LOAD MyField, Count(MyField) as CountMyField Group By MyField;

LOAD * Where FieldIndex('MyField', MySubField);

LOAD MyField, Left(MyField,IterNo()) as MySubField

Resident table1 While IterNo()<=Len(MyField);

hope this helps

regards

Marco

Anonymous
Not applicable
Author

Hi Massimo,

I hope this script will give you better understanding, when I'm going to add one more field then nothing is going to be showed, please check.

a:

load *, len(field) as len inline [

field, value

ABC-CDE, 2

ABC-CDEFG, 2

XYZ-AB-001, 3

XYZ-AB-001-C1,3

AAABBB, 4

ZZZZZ, 5

ZZZ, 5

ZZZZ, 5

];

b:

load field where match=1;

load

  field,

  len,

  value,

  if(wildmatch(field, peek(field) & '*') and len(peek(field))>0, 1, 0) as match

Resident

  a

order by field, len;

DROP Table a;