Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Newbie mapping question

So... I have a list of items in my data-set, each of which belongs to a higher-level category. However, the categories are not in the data. I need to add a new field to each record in the data (onload) that takes it's value from a mapping table.

For example:

raw data:

RecordItem
1car
2apple
3car
4pear
5boat
6plane
7apple
8car
9pear

mapping (lookup) table

ItemCategory
carTransport
appleFruit
pearFruit
boatTransport
planeTransport

Data after load:

RecordItemCategory
1carTransport
2appleFruit
3carTransport
4pearFruit
5boatTransport
6planeTransport
7appleFruit
8carTransport
9pearFruit

I've had a look at the online help on how to create the mapping table, and create a new field in which to populate it, but the peeny hasn't dropped yet

All help much appreciated.

Thanks...

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Seems to work for me for this simple sample:

MAP:

Mapping load Item, Category Inline [

Item, Category

"Item with commas, and some brackets (here, as you can see)", "Category_A"

];

DATA:

LOAD ApplyMap('MAP',Item) as Category, Item INLINE [

Item

"Item with commas, and some brackets (here, as you can see)"

];

Maybe your DATA Item values don't get read in as expected and therefore doesn't match your mapping?

View solution in original post

7 Replies
Nicole-Smith

RawData:

LOAD Record, Item

FROM RawData;

LEFT JOIN (RawData)

LOAD * INLINE [

Item,Category

car,Transport

apple,Fruit

pear,Fruit

boat,Transport

plane,Transport

];

Note: For the RawData, replace that with the excel or SQL or wherever you're loading it from.  You may also need to replace the table name (as well as in the left join).

swuehl
MVP
MVP

MAP:

MAPPING LOAD Item, Category INLINE [

Item, Category

car, Transport

apple, Fruit

pear, Fruit

....

];

LOAD Record,

          Item,

          applymap('MAP', Item) as Category

FROM raw_data;

Not applicable
Author

Both very helpful, thanks.

One last thing to crack. What do I do if my Categories have a comma in them?

Thanks...

swuehl
MVP
MVP

Try quoting the value

LOAD A,B INLINE [

A, B

1, "Hi, all"

];

Not applicable
Author

Yeah, that's what I thought, too.

Actually, it's the ITEM that has commas in, not the category. I've tried quoting both, but it doesn't work.

Mapping load Item, Category Inline [

...

"Item with commas, and some brackets (here, as you can see)", "Category_A"

...

];

swuehl
MVP
MVP

Seems to work for me for this simple sample:

MAP:

Mapping load Item, Category Inline [

Item, Category

"Item with commas, and some brackets (here, as you can see)", "Category_A"

];

DATA:

LOAD ApplyMap('MAP',Item) as Category, Item INLINE [

Item

"Item with commas, and some brackets (here, as you can see)"

];

Maybe your DATA Item values don't get read in as expected and therefore doesn't match your mapping?

Not applicable
Author

How odd.

I copied the field value back in and it worked. There must have been a typo somewhere.

Thanks for all your help.