Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
gfisch13
Creator II
Creator II

Keyword Listbox

Hi All -

I'm doing a project where I have to classify some data according to keywords found in several other fields.  Below is an example of script I created in another application.  I would like the words that lead off each line (Shopping, Flight, Transport......) to become a new field in my table so that it would be selectable from a list box.  PRCH_HRCH_NM and MCC_DSCR are fields in my dataset which include my search words.  My intention is to take this additional application out of service and have QV directly create this field.

Any help would be greatly appreciated.

Thanks!

George

'Shopping' IF FINDMULTI( PRCH_HRCH_NM, "Clothing" )

'Shopping' IF FINDMULTI( MCC_DSCR,"Pet shop","Motion","Building","jigsaw","Perfume","Propane","Fuel dealers","Drapery","Musical","Warehous","Drugs","Paint","Electrical parts","Photof" )

  'Flight' IF FINDMULTI( MCC_DSCR"travel agen","Visa","ESTA" )

  'Flight' IF FINDMULTI( PRCH_HRCH_NM, "Airlines" )

  'Transport' IF FINDMULTI( PRCH_HRCH_NM, "Vehicle","Automobile","washes","Transp" )

  'Transport' IF FINDMULTI( MCC_DSCR,"Automo","Taxi","Cabs","Bus lines","Washes","Transp")

  'CCC Info' IF FINDMULTI( PRCH_HRCH_NM, "Invalid MCC" )

  'Accomodation' IF FINDMULTI( PRCH_HRCH_NM, "Lodging" )

  'Food/Drink' IF FINDMULTI( PRCH_HRCH_NM, "Eating","Food" )

  'Health' IF FINDMULTI( PRCH_HRCH_NM, "Health service" )

  'Health' IF FINDMULTI( MCC_DSCR,"dental","medical")

  'Post/Gov' IF FINDMULTI( MCC_DSCR,"Postal","Courier","Freight")

  'Org/Sch/College' IF FINDMULTI( MCC_DSCR,"Organi","School","College","Associa","Subscrip")

  'Rec or Event' IF FINDMULTI( MCC_DSCR,"athltic","Golf","Amusement","Bands","Tourist","Caterers","Recreation","Bowling","Theatrical","Dolphin")

  'Govt' IF FINDMULTI( PRCH_HRCH_NM, "Govern" )

  'Miscellaneous' IF FINDMULTI( MCC_DSCR,"elsewhere")

  'Cable/Tele' IF FINDMULTI( MCC_DSCR,"cable","Telecom","Phone")

  'Cable/Tele' IF FINDMULTI( MCC_DSCR,"Book","Computer","Florist","Direct market")

  'Miscellaneous' IF FINDMULTI( MCC_DSCR,"data prc","consulting","Information","Print","Advertis","Engineering","premiums","Preparation","Residential","Contractors")

  'Miscellaneous'

13 Replies
pradosh_thakur
Master II
Master II

did you try the function WILDMATCH() in QV?

regards

Pradosh

Learning never stops.
gfisch13
Creator II
Creator II
Author

I have not as I'm new to the software and don't fully understand how to script this task out.

fvelascog72
Partner - Specialist
Partner - Specialist

Hi,

Try with attached file.

Saludos.

felipedl
Partner - Specialist III
Partner - Specialist III

Using the attached Excel classification, you could use something like the bellow script to classify:

DataSet:

Load * Inline

[

Field,Desc

PRCH_HRCH_NM,Vehicle

PRCH_HRCH_NM,Lodging

PRCH_HRCH_NM,Clothing

MCC_DSCR,Visa

];

Tmp:

LOAD Classification,

    Field,

    Item

FROM

C:\Users\eferibe\Desktop\Sample.xlsx

(ooxml, embedded labels, table is Sheet1);

left join (DataSet)

Load

Field,

Item as Desc,

Classification

Resident Tmp;

drop table Tmp;

effinty2112
Master
Master

Hi George,

I pasted your text into the attached txt file then ran this script:

Lines:

Load

Distinct

Subfield(SubField(Lines,' ',1),Chr(39),2) as FieldValues;

LOAD Lines

FROM

Lines.txt

(txt, codepage is 1252, embedded labels, delimiter is '|', no quotes);

to get:

FieldValues
Accomodation
Cable/Tele
CCC
Flight
Food/Drink
Govt
Health
Miscellaneous
Org/Sch/College
Post/Gov
Rec
Shopping
Transport

Cheers

Andrew

gfisch13
Creator II
Creator II
Author

Appreciate all your responses, what I'm not understanding is how this applies where there are multiple values in the search field.   How do these procedures account for that?

effinty2112
Master
Master

Hi George,

Maybe I misunderstood your need. Instead of one field you need 13 fields like for example

Flight

Visa

EST

Airlines

Is that right?

Andrew

gfisch13
Creator II
Creator II
Author

I think its me not being clear enough, here is a screen shot of what the table looks like when I'm done applying the code I show above..............(Flight, doesn't look to be calculating quite right at the moment but I think this picture will help.  The CC_Classification field is the one I'm creating...........

Classification.JPG

effinty2112
Master
Master

Hi george,

I hope this is helpful:

Lines:

Load

*

Where Not WildMatch(Values,'*PRCH_HRCH_NM*','*MCC_DSCR*');

Load

Distinct

Subfield(SubField(Lines,' ',1),Chr(39),2) as CC_Classifications,

if(WildMatch(Lines,'*PRCH_HRCH_NM*'),'PRCH_HRCH_NM','MCC_DSCR') as [Search Fields],

Trim(

PurgeChar(

PurgeChar(

Subfield(

SubField(

Right(Lines, Len(Lines) - len(SubField(Lines,' ',1))),

'(',2),

','),'"'),')'))

as Values;

LOAD Lines

FROM

Lines.txt

(txt, codepage is 1252, embedded labels, delimiter is '|', no quotes);

Giving:

CC_Classifications Search Fields Values
AccomodationPRCH_HRCH_NMLodging
Cable/TeleMCC_DSCRBook
Cable/TeleMCC_DSCRcable
Cable/TeleMCC_DSCRComputer
Cable/TeleMCC_DSCRDirect market
Cable/TeleMCC_DSCRFlorist
Cable/TeleMCC_DSCRPhone
Cable/TeleMCC_DSCRTelecom
CCCPRCH_HRCH_NMInvalid MCC
FlightPRCH_HRCH_NMAirlines
FlightMCC_DSCRESTA
FlightMCC_DSCRtravel agen
FlightMCC_DSCRVisa
Food/DrinkPRCH_HRCH_NMEating
Food/DrinkPRCH_HRCH_NMFood
GovtPRCH_HRCH_NMGovern
HealthMCC_DSCRdental
HealthPRCH_HRCH_NMHealth service
HealthMCC_DSCRmedical
MiscellaneousMCC_DSCRAdvertis
MiscellaneousMCC_DSCRconsulting
MiscellaneousMCC_DSCRContractors
MiscellaneousMCC_DSCRdata prc
MiscellaneousMCC_DSCRelsewhere
MiscellaneousMCC_DSCREngineering
MiscellaneousMCC_DSCRInformation
MiscellaneousMCC_DSCRpremiums
MiscellaneousMCC_DSCRPreparation
MiscellaneousMCC_DSCRPrint
MiscellaneousMCC_DSCRResidential
Org/Sch/CollegeMCC_DSCRAssocia
Org/Sch/CollegeMCC_DSCRCollege
Org/Sch/CollegeMCC_DSCROrgani
Org/Sch/CollegeMCC_DSCRSchool
Org/Sch/CollegeMCC_DSCRSubscrip
Post/GovMCC_DSCRCourier
Post/GovMCC_DSCRFreight
Post/GovMCC_DSCRPostal
RecMCC_DSCRAmusement
RecMCC_DSCRathltic
RecMCC_DSCRBands
RecMCC_DSCRBowling
RecMCC_DSCRCaterers
RecMCC_DSCRDolphin
RecMCC_DSCRGolf
RecMCC_DSCRRecreation
RecMCC_DSCRTheatrical
RecMCC_DSCRTourist
ShoppingMCC_DSCRBuilding
ShoppingPRCH_HRCH_NMClothing
ShoppingMCC_DSCRDrapery
ShoppingMCC_DSCRDrugs
ShoppingMCC_DSCRElectrical parts
ShoppingMCC_DSCRFuel dealers
ShoppingMCC_DSCRjigsaw
ShoppingMCC_DSCRMotion
ShoppingMCC_DSCRMusical
ShoppingMCC_DSCRPaint
ShoppingMCC_DSCRPerfume
ShoppingMCC_DSCRPet shop
ShoppingMCC_DSCRPhotof
ShoppingMCC_DSCRPropane
ShoppingMCC_DSCRWarehous
TransportMCC_DSCRAutomo
TransportPRCH_HRCH_NMAutomobile
TransportMCC_DSCRBus lines
TransportMCC_DSCRCabs
TransportMCC_DSCRTaxi
TransportMCC_DSCRTransp
TransportPRCH_HRCH_NMTransp
TransportPRCH_HRCH_NMVehicle
TransportMCC_DSCRWashes
TransportPRCH_HRCH_NMwashes

Regards

Andrew