Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
lfalmoguera
Creator
Creator

Best Match solution for numbers?

Hi all,

I  am trying to find a solution two compara two rows of numbers and get the best match result.

uick example:

   

tableA tableB Result Table
numberA numberMatchResult numberAResult
610 6A 610A
629 62B 629B
628 628A 628A
62974 6297C 62974C
6510 651A 6510A
6298 63B 63B
64 64C 64C
65 65A
66 66A
67 67A
68 68A
69 69A

Any quick to achieve it?

I am trying with mathc(), wildmatch() and several loops, but I am struggling.

Thanks a lot in advance.

Regards.

3 Replies
swuehl
MVP
MVP

Maybe like

TableA:

LOAD * INLINE [

NumberA

610

629

628

62974

6510

6298

64

65

66

67

68

69

];

TableB:

LOAD *, Len(NumberMatch) as LenMatch INLINE [

NumberMatch, Result

6,A

62,B

628,A

6297,C

651,A

63,B

64,C

];

MAP:

MAPPING

LOAD '~'&NumberMatch, '<'&Result&'>'

Resident TableB

ORDER BY LenMatch desc;

Result:

LOAD NumberA,

          Textbetween(Mapsubstring('MAP','~'&NumberA),'<','>') as Result

Resident TableA;

lfalmoguera
Creator
Creator
Author

Wow!

It worked perfectly! I don´t know how scalable it would be as I need to cross quite a million records, but it worked so fine!

Thanks a lot!

PD. The worst part is that I do not undersand the code and how it works : )

swuehl
MVP
MVP

Remove the Textbetween from the last load to see the mapping, this should make it easier to understand.

(I assume you know how mapping works in Qlik, if not, start with MAPPING LOAD and MapSubString() function in the HELP):

Result:

LOAD NumberA,

          Mapsubstring('MAP','~'&NumberA) as Result

Resident TableA;