Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Transform a value in a field to its own field

hi

What i want to do is take the set value of 'product' which is in the 'Field(s)' column and use this to create a new column called 'product' and populate the  'Values' for this against every set 'Identifier'

Example here is how my current data looks :-

     

DateS.NoIdentifierClient1Client2Field(s)Value(s)
9/1/201831identifier 1DaveAlfTimeT10:44:21Z
9/1/201831identifier 1DaveAlfclient 1Dave
9/1/201831identifier 1DaveAlfclient 2Alf
9/1/201831identifier 1DaveAlfcountryGermany
9/1/201831identifier 1DaveAlfproductOranges
9/1/201832identifier 2FredSamTimeT10:44:21Z
9/1/201832identifier 2FredSamclient 1Dave
9/1/201832identifier 2FredSamclient 2Alf
9/1/201832identifier 2FredSamcountryGermany
9/1/201832identifier 2FredSamproductApples
9/1/201833identifier 3WayneColinTimeT10:44:21Z
9/1/201833identifier 3WayneColinclient 1Dave
9/1/201833identifier 3WayneColinclient 2Alf
9/1/201833identifier 3WayneColincountryGermany
9/1/201833identifier 3WayneColinproductPears
9/1/201834identifier 4DaveAlfTimeT10:44:21Z
9/1/201834identifier 4DaveAlfclient 1Dave
9/1/201834identifier 4DaveAlfclient 2Alf
9/1/201834identifier 4DaveAlfcountryGermany
9/1/201834identifier 4DaveAlfproductPears

I want to take the value of 'Product' in the 'Fields' column and with its value create a new column BUT ensure it is applied for each Identifier linked to that (it would almost be like Transposing just those two columns) It should therefore end up looking like this

   

DateS.NoIdentifierClient1Client2Field(s)Value(s)Product
9/1/201831identifier 1DaveAlfTimeT10:44:21ZOranges
9/1/201831identifier 1DaveAlfclient 1DaveOranges
9/1/201831identifier 1DaveAlfclient 2AlfOranges
9/1/201831identifier 1DaveAlfcountryGermanyOranges
9/1/201831identifier 1DaveAlfproductOrangesOranges
9/1/201832identifier 2FredSamTimeT10:44:21ZApples
9/1/201832identifier 2FredSamclient 1DaveApples
9/1/201832identifier 2FredSamclient 2AlfApples
9/1/201832identifier 2FredSamcountryGermanyApples
9/1/201832identifier 2FredSamproductApplesApples
9/1/201833identifier 3WayneColinTimeT10:44:21ZPears
9/1/201833identifier 3WayneColinclient 1DavePears
9/1/201833identifier 3WayneColinclient 2AlfPears
9/1/201833identifier 3WayneColincountryGermanyPears
9/1/201833identifier 3WayneColinproductPearsPears
9/1/201834identifier 4DaveAlfTimeT10:44:21ZPears
9/1/201834identifier 4DaveAlfclient 1DavePears
9/1/201834identifier 4DaveAlfclient 2AlfPears
9/1/201834identifier 4DaveAlfcountryGermanyPears
9/1/201834identifier 4DaveAlfproductPearsPears


Its important to view this as not each line is a seperate line item BUT every 5 lines are related to 1 item

Also not sure if its important to note that the values in 'Field(s)' WILL remain static all other fields are going to be changeable

any help gratefully received

thanks

1 Solution

Accepted Solutions
rajivmeher
Creator
Creator

Hi

What is the data source you are trying to access? Is it a excel file? If yes, please try the following:

Value_Map:

Mapping      LOAD

select           Identifier,

                    [Value(s)]

FROM

(ooxml, embedded labels, table is Sheet1)

WHERE [Field(s)] = 'product';

TestTable:

LOAD *,

ApplyMap('Value_Map',Identifier, NULL()) as PRODUCT

FROM

(ooxml, embedded labels, table is Sheet1);

DROP TABLE Value_Map;


Regards

Rajiv.

View solution in original post

18 Replies
rajivmeher
Creator
Creator

Hi jfreeman

Please see if applymap can be a solution for this?

See the code below based on your example:

Value_Map:

MAPPING LOAD

SQL

SELECT Identifier,

Value

FROM TABLE

WHERE Field = 'product';


TABLE:

LOAD *,

APPLYMAP('Value_Map', Identifier, NULL()) AS Product;


SQL

SELECT *

FROM TABLE;


On the above code I am picking unique combination of Identifier and value combination to a mapping table. Which is later applied to the whole table where their is a match with a identifier, the corresponding value will be assisned as product.


Regards

Rajiv.

trdandamudi
Master II
Master II

May be as below:


Data:
Load * Inline [
Date,S.No,Identifier,Client1,Client2,Fields,Values
9/1/2018, 31, identifier 1, Dave, Alf, Time, T10:44:21Z
9/1/2018, 31, identifier 1, Dave, Alf, client 1, Dave
9/1/2018, 31, identifier 1, Dave, Alf, client 2, Alf
9/1/2018, 31, identifier 1, Dave, Alf, country, Germany
9/1/2018, 31, identifier 1, Dave, Alf,product, Oranges
9/1/2018, 32 ,identifier 2, Fred, Sam, Time, T10:44:21Z
9/1/2018, 32, identifier 2, Fred, Sam, client 1, Dave
9/1/2018, 32, identifier 2, Fred, Sam, client 2, Alf
9/1/2018, 32, identifier 2, Fred, Sam, country, Germany
9/1/2018, 32, identifier 2, Fred, Sam,product, Apples
9/1/2018, 33, identifier 3, Wayne, Colin, Time, T10:44:21Z
9/1/2018, 33, identifier 3, Wayne, Colin, client 1, Dave
9/1/2018, 33, identifier 3, Wayne, Colin, client 2, Alf
9/1/2018, 33, identifier 3, Wayne, Colin, country, Germany
9/1/2018, 33, identifier 3, Wayne, Colin,product, Pears
9/1/2018, 34, identifier 4, Dave, Alf, Time, T10:44:21Z
9/1/2018, 34, identifier 4, Dave, Alf, client 1, Dave
9/1/2018, 34, identifier 4, Dave, Alf, client 2, Alf
9/1/2018, 34, identifier 4, Dave, Alf, country, Germany
9/1/2018, 34, identifier 4, Dave, Alf,product, Pears
]
;

MapTable:
MAPPING LOAD  
Identifier,
Values
RESIDENT Data
Where Fields='product';


NoConcatenate
Final:
Load *,
ApplyMap('MapTable', Identifier, NULL()) AS Product
Resident Data;

Drop Table Data;

santhana
Contributor III
Contributor III

Hi jemma freeman ,

kindly find the below script and use it will give you a desired output

STEP1:

LOAD * Inline[

Date, S.No, Identifier, Client1, Client2, Field(s), Value(s)

9/1/2018, 31, identifier 1, Dave, Alf, Time, T10:44:21Z

9/1/2018, 31, identifier 1, Dave, Alf, client 1, Dave

9/1/2018, 31, identifier 1, Dave, Alf ,client 2, Alf

9/1/2018, 31, identifier 1, Dave, Alf ,country, Germany

9/1/2018, 31, identifier 1, Dave, Alf ,product, Oranges

9/1/2018, 32, identifier 2, Fred, Sam ,Time, T10:44:21Z

9/1/2018, 32, identifier 2, Fred, Sam ,client 1, Dave

9/1/2018, 32, identifier 2, Fred, Sam ,client 2, Alf

9/1/2018, 32, identifier 2, Fred, Sam ,country, Germany

9/1/2018, 32, identifier 2, Fred, Sam ,product, Apples

9/1/2018, 33, identifier 3, Wayne, Colin, Time, T10:44:21Z

9/1/2018, 33, identifier 3, Wayne, Colin, client 1, Dave

9/1/2018, 33, identifier 3, Wayne, Colin, client 2, Alf

9/1/2018, 33, identifier 3, Wayne, Colin, country, Germany

9/1/2018, 33, identifier 3, Wayne, Colin, product, Pears

9/1/2018, 34, identifier 4, Dave, Alf, Time, T10:44:21Z

9/1/2018, 34, identifier 4, Dave, Alf, client 1, Dave

9/1/2018, 34, identifier 4, Dave, Alf, client 2, Alf

9/1/2018, 34, identifier 4, Dave, Alf, country ,Germany

9/1/2018, 34, identifier 4, Dave, Alf, product ,Pears];


LOAD Date,

S.No,

Identifier,

Client1,

Client2,

[Field(s)],

[Value(s)],

'*' AS TEMP Resident STEP1;

join



LOAD

S.No,

[Value(s)] as Product,

'*' AS TEMP Resident STEP1 where [Field(s)]='product';

DROP Table STEP1;

Capture.PNG

Anonymous
Not applicable
Author

thanks Rajiv i will give this a go now and let you know

Anonymous
Not applicable
Author

thanks Santhana and Thirumala my one concern with your solution is that i need to upload data to this daily and all the values under the fields will constantly change. I will also be uploading anything from 10 rows to 1million rows+ at a time so i do not think your solution is potentially going to work as step 1 includes all the current values? unless ive misunderstood how to apply this?

trdandamudi
Master II
Master II

Based on your question and the solution you got, I do not see any issue. Can you please try it out and let us know and we can go from there.

Anonymous
Not applicable
Author

thanks Rajiv i was also thinking along the lines of an Apply Map but couldnt make it work. Ive tried your solution but it will not register SQL after the Mapping Load or the command 'select'. Ive taken everything literal is this correct? this is what ive entered :-

Value_Map:

Mapping LOAD

SQL

select Identifier,

[Value(s)]

From Table

Where [Field(s)] = 'product';

Table:

LOAD*,

ApplyMap('Value_Map',Identifier, NULL()) as PRODUCT;

SQL

Select *

from Table;

Anonymous
Not applicable
Author

hi, i have tried but after inputing LOAD * Inline it does then not like the [ - i have never used 'Inline' before is there an easier way to enter the fields and data? also when i come to reload new data in and the values change and the volume of data changes will QV know to automtically update this table in the script? many thanks for your help

trdandamudi
Master II
Master II

I don't see that issue on my side and attached is the file:

Your question:

also when i come to reload new data in and the values change and the volume of data changes will QV know to automtically update this table in the script?

The answer is "Yes".