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: 
KevinJ
Contributor III
Contributor III

Extracting Word from a text String

I have this data. I want to extract it to OPEX, CAPEX, GREENLANE and use it as a column. Is that possible?

it will be a measure or dimension? Is that Possible?

Initial Table: 

Bacolod LBE OPEX
Cebu LBE GRN LANE
Terminal Ops VISAYAS GRN LANE
Surigao LBE OPEX
Terminal Ops MINDANAO OPEX
Manila LBE GRN LANE
Manila LBE GRN LANE
Bacolod LBE OPEX
Zamboanga LBE OPEX
Cebu LBE GRN LANE
Terminal Ops MINDANAO OPEX

 

RESULTS:

Bacolod LBE OPEX OPEX
Cebu LBE GRN LANE GRN LANE
Terminal Ops VISAYAS GRN LANE GRN LANE
Surigao LBE OPEX OPEX
Terminal Ops MINDANAO OPEX OPEX
Manila LBE GRN LANE GRN LANE
Manila LBE GRN LANE GRN LANE
Bacolod LBE OPEX OPEX
Zamboanga LBE OPEX OPEX
Cebu LBE GRN LANE GRN LANE
Terminal Ops MINDANAO OPEX OPEX

 

Labels (2)
2 Solutions

Accepted Solutions
marcus_sommer

I suggest to do the job within the data-model, maybe with:

pick(wildmatch(MyField, '*OPEX*', '*CAPEX*', '*GRNLANE*'),
   'OPEX', 'CAPEX', 'GREENLANE') as MyFieldExtract

View solution in original post

Anil_Babu_Samineni

@KevinJ Try this way?

If(Right(FieldName, 4)='OPEX', 'OPEX', SubField(FieldName, ' ', -2) & ' ' & SubField(FieldName, ' ', -1))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful

View solution in original post

3 Replies
LRuCelver
Partner - Creator III
Partner - Creator III

If you only have the three words you need to extract and they always appear at the end of the texts, you can use a few nested IFs to create the 2nd column. This can be done as both a measure or a dimension.

If(Right(TEXTFIELD, 4) = 'OPEX', 'OPEX',
If(Right(TEXTFIELD, 5) = 'CAPEX', 'CAPEX',
If(Right(TEXTFIELD, 9) = 'GREENLANE', 'GREENLANE',
'-' // Else. Delete this row or replace with Null() if this should be Null.
)))

If you need a more dynamic solution, creating a dimension might be the easier solution as long as the words always appear at the end. If they don't, it'll be a lot more complicated.

marcus_sommer

I suggest to do the job within the data-model, maybe with:

pick(wildmatch(MyField, '*OPEX*', '*CAPEX*', '*GRNLANE*'),
   'OPEX', 'CAPEX', 'GREENLANE') as MyFieldExtract

Anil_Babu_Samineni

@KevinJ Try this way?

If(Right(FieldName, 4)='OPEX', 'OPEX', SubField(FieldName, ' ', -2) & ' ' & SubField(FieldName, ' ', -1))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful