Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Create mapping table using substrings

Hi,

I have data in the following formats:-

There are roughly 50 ATB codes

ATB CodeDescriptionCompatible CIB Codes
1Central0111-6423, 7012-7018, 6603
2Local0111-6423, 7012-7018

+

There are roughly 500 CIB Codes

CIB CodesDesc
0111Desc 1
0112Desc 2
0123Desc 3
0124Desc 4

I want to create a row based table of acceptable ATB and CIB combinations that would end up in this format:-

ATB CodeCIB Codes
10111
10112
10123
10124

Is this doable using Qlikview? If so what script commands would one use?

Thanks

Stuart

1 Solution

Accepted Solutions
Not applicable
Author

Hi Stuart,

I think the attached should do what you are looking for.

Hope that helps

Joe

View solution in original post

18 Replies
ramoncova06
Specialist III
Specialist III

Mapping Functions

The ApplyMap function is used for mapping any expression to a previously loaded mapping table. The syntax is:

applymap('mapname', expr [ , defaultexpr ] )

where:

mapname is the name of a mapping table that has previously been created through the mapping load or the mapping select statement (see Mapping). Its name must be enclosed by single, straight Quotation Marks in Scripting.

expr is the expression, the result of which should be mapped.

defaultexpr is an optional expression which will be used as a default mapping value if the mapping table does not contain a matching value for expr. If no default value is given, the value of expr will be returned as is.

Examples:

// Assume the following mapping table:

map1:

mapping load * inline [

x, y

1, one

2, two

3, three ] ;

ApplyMap ('map1', 2 ) returns ' two'

ApplyMap ('map1', 4 ) returns 4

ApplyMap ('map1', 5, 'xxx') returns 'xxx'

ApplyMap ('map1', 1, 'xxx') returns 'one'

ApplyMap ('map1', 5, null( ) ) returns NULL

ApplyMap ('map1', 3, null( ) ) returns 'three'

The MapSubstring function is used to map parts of any expression to a previously loaded mapping table. The mapping is case sensitive and non-iterative and substrings are mapped from left to right. The syntax is:

mapsubstring('mapname', expr)

This function can be used for mapping parts of any expression on a previously loaded mapping table. The mapping is case sensitive and non-recursive. The substrings are mapped from the left to the right. Mapname is the name of a mapping table previously read by a mapping load or a mapping select statement (see Mapping). The name must be enclosed by single straight quotation marks. Expr is the expression whose result should be mapped by substrings.

Examples:

// Assume the following mapping table:

map1:

mapping load * inline [

x, y

1, <one>

aa, XYZ

x, b ] ;

MapSubstring ('map1', 'A123') returns 'A<one>23'

MapSubstring ('map1', 'baaar') returns 'bXYZar'

MapSubstring ('map1', 'xaa1') returns 'bXYZ<one>'

QlikView 11.20 SR6

avinashelite

Hi Stuart,

If you just need to have data from table to be linked with all the  data from table 2 then concatenate would do, But what the mapping for 2 here? I.e how you identify 1 showed be linked with 0111,0112,0113 etc ?? and even 2 data show be linked with the 0111,0112,0113 etc? if that is the case then simply concatenate or if their is any condition please specify that mapping condition

Not applicable
Author

Avinash that is the part I am struggling with.

We have one text string that says ATB 1 is allowed to use CIB codes 0111-6423.

Within the range 0111-6423 there are actually 290 CIB codes.

The target, for example,  is to create the mapping table with 290 lines for ATB 1

ramoncova06
Specialist III
Specialist III

can you share a sample data set, you could probably apply an if condition checking if the mapping exists or not

avinashelite

IF you simple need to have create column for the records in CIB code then just use concatenate between those to tables that will create a row for each record in the ATB with a record in the CIB

Hope this solve's the problem

Not applicable
Author

have attached a sample dummy data set

avinashelite

did you tired with concatenation

Not applicable
Author

I cant see how that will work as I need to get the table in the following format:-

ATB CodeCIB Codes
10111
10112
10123
10124
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Try this:


_ATB:
LOAD ATB,
[Compatible ATB Codes],
SubStringCount([Compatible ATB Codes], ',') + 1 as Subfields
FROM
[sample data set.xlsx]
(
ooxml, embedded labels, table is [ATB Codes]);

MaxSubfields:
LOAD
max(Subfields) as maxSubfields
RESIDENT _ATB;

Let vMaxSubfields = peek('maxSubfields', -1);

DROP TABLE MaxSubfields;

for n = 1 to vMaxSubfields
TRACE $(n);

ATB:
LOAD
ATB,
Subfield([Compatible ATB Codes], ',', $(n)) as CompatibleATBCode,
$(n) as loop
RESIDENT _ATB
WHERE $(n) <= Subfields
;

next n

DROP TABLE _ATB;