Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

MVP
MVP

Re: Split Name Field

This would be so much easier if QV supported regular expressions natively

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Highlighted
Partner
Partner

Re: Split Name Field

Hi,

Try This

1) create a mapping file

Map_Name:
Mapping
LOAD * INLINE [
Name, MapNmae
A, _A
B, _B
C, _C
D, _D
E, _E
F, _F
G, _G
H, _H
I, _I
J, _J
K, _K
L, _L
M, _M
N, _N
O, _O
P, _P
Q, _Q
R, _R
S, _S
T, _T
U, _U
V, _V
W, _W
X, _X
Y, _Y
Z, _Z
]
;

2) use MapSubString function to find the first & last name

subfield(MapSubString('Map_Name',Name),'_',2) AS FirstName,
subfield(MapSubString('Map_Name',Name),'_',3) AS LastName

Example:

Map_Name:
Mapping
LOAD * INLINE [
Name, MapNmae
A, _A
B, _B
C, _C
D, _D
E, _E
F, _F
G, _G
H, _H
I, _I
J, _J
K, _K
L, _L
M, _M
N, _N
O, _O
P, _P
Q, _Q
R, _R
S, _S
T, _T
U, _U
V, _V
W, _W
X, _X
Y, _Y
Z, _Z
]
;


Test:
LOAD * INLINE [
Name
PaulKelly(6653),
JoeBloggs(6621)
]
;

Test1:
load
Name,
subfield(MapSubString('Map_Name',Name),'_',2) AS FirstName,
subfield(MapSubString('Map_Name',Name),'_',3) AS LastName
resident Test;

drop table Test;

-Sathish

MVP
MVP

Re: Split Name Field

You can actually do it like this with Regular Expressions by using a function written in VBScript and call it from the load script as a normal function. The VBScript function has to be put in the Tools / Module. I have attached the sample app that these screenshots are taken from. Even though the Load Script language have no Regular Expression functions you can use the RegEx support in VBScript.

2016-02-12 #2.PNG

2016-02-12 #1.PNG

The RegEx VBScript functions are from the QlikFix blog of BarryHarmsen and copied from his example application that you can find there. Search for Regular Expressions in QlikView on his blog.

MVP
MVP

Re: Split Name Field

Well ... QV Load Script supports calling VBScript Functions out of the box. VBScript has a built-in RegEx object that can be used. So QlikView does not need any extension or calling external programs. Have a look at how it is done further down in this thread.

MVP
MVP

Re: Split Name Field

@Petter

I know you can call them via VBScript, and somewhere I have a sample that does it, but I would like to see native support for Regex which is long overdue. I suspect that a properly designed native implementation will run a lot faster than the VBScript approach on a large data set.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
MVP
MVP

Re: Split Name Field

Yes you are absolutely right - it would be better.

pkelly
Valued Contributor

Re: Split Name Field

Thanks Petter,

Ended up with...

TelephoneSystem:
LOAD *,
SubField(TempParsedAgent,';',1 ) AS tel_FirstName,
SubField(TempParsedAgent,';',2 ) & IF(IsNull(SubField(TempParsedAgent,';',3)), '', SubField(TempParsedAgent,';',3))  AS tel_LastName;

LOAD
201511 AS %AnalysisPeriodKey,

PurgeChar(RIGHT(Agent,6), '()') AS TempExtension,

RegExFind(Agent , '[A-Z][a-z]*' , ';' , 0 ) AS TempParsedAgent

FROM (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

Had to add to last name to cover names like McDonald.

MVP
MVP

Re: Split Name Field

Here is the beauty (or ugliness - depending on your prespective) of regular expressions:

You can cater for MacXxxxxx McXxxxxx O'Xxxxxx X'Xxxxxx   with this regex:

[A-Z]([a-z]{1,2}|')[A-Z][a-z]*|[A-Z][a-z]*