Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Friends
In may data table the following field exits
BANK_BRANCH
7287-001
7287-030
7287-050
7268-001
7750-005
if(SUBFIELD(BANK_BRANCH,1,4)='7287','SEYLAN','OTHERS')AS BANK,
I have written above syntax and but in the results Retrun 'OTHERS' for record. Pls tell where I am wrong
Hi,
It should be
if(SUBFIELD(BANK_BRANCH,'-',1)='7287','SEYLAN','OTHERS')AS BANK
Regards,
Greeshma
Hi,
It should be
if(SUBFIELD(BANK_BRANCH,'-',1)='7287','SEYLAN','OTHERS')AS BANK
Regards,
Greeshma
Hi,
Your subfield Syntax is wrong
try like
if(SUBFIELD(BANK_BRANCH,'-',1)='7287','SEYLAN','OTHERS')AS BANK,
Regards
You should give the separator, its not like the mid function
if(SUBFIELD(BANK_BRANCH, '-',1)='7287', 'SEYLAN', 'OTHERS') AS BANK
Regards,
Celambarasan
Thanks all Can you please explain me why syntax is written as below
BANK_BRANCH,'-',1
See in Help Menu
You will get very good explanation of Subfield()
Regards
Whatever function you came through in qlikview is well explained in QlikView help itself
From Help file
subfield(s, 'delimiter' [ , index ] )
In its three-parameter version, this script function returns a given substring from a larger string s with delimiter 'delimiter'. index is an optional integer denoting which of the substrings should be returned. If index is omitted when subfield is used in a field expression in a load statement, the subfield function will cause the load statement to automatically generate one full record of input data for each substring that can be found in s.
In its two-parameter version, the subfield function generates one record for each substring that can be taken from a larger string s with the delimiter 'delimiter'. If several subfield functions are used in the same load statement, the Cartesian product of all combinations will be generated.
Examples:
(For three parameters)
subfield(S, ';' ,2) returns 'cde' if S is 'abc;cde;efg'
subfield(S, ';' ,1) returns NULL if S is an empty string
subfield(S, ';' ,1) returns an empty string if S is ';'
Subfield() is used to extract substring components from a parent string field, where the original record fields consist of two or more parts separated by a delimiter.
The Subfield() function can be used, for example, to extract first name and surname from a list of records consisting of full names, the component parts of a path name, or for extracting data from comma-separated tables.
If you use the Subfield() function in a LOAD statement with the optional field_no parameter left out, one full record will be generated for each substring. If several fields are loaded using Subfield() the Cartesian products of all combinations are created.
Syntax:
SubField(text, delimiter[, field_no ])
Return data type: string
Arguments:
Argument | Description |
---|---|
text | The original string. This can be a hard-coded text, a variable, a dollar-sign expansion, or another expression. |
delimiter | A character within the input text that divides the string into component parts. |
field_no | The optional third argument is an integer that specifies which of the substrings of the parent string text is to be returned. Use the value 1 to return the first substring, 2 to return the second substring, and so on. A negative value causes the substring to be extracted from the right-hand side of the string. That is, the string search is from right to left, instead of left to right, if field_no is a positive value. |
Example | Result | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SubField(S, ';' ,2) | Returns 'cde' if S is 'abc;cde;efg'. | ||||||||||||||||||||||||||||||||||||||||||
SubField(S, ';' ,1) | Returns NULL if S is an empty string. | ||||||||||||||||||||||||||||||||||||||||||
SubField(S, ';' ,1) | Returns an empty string if S is ';'. | ||||||||||||||||||||||||||||||||||||||||||
Add the example script to your app and run it. Then add, at least, the fields listed in the results column to a sheet in your app to see the result. FullName: LOAD * inline [ Name 'Dave Owen' 'Joe Tem' ]; SepNames: Load Name, SubField(Name, ' ',1) as FirstName, SubField(Name, ' ',-1) as Surname Resident FullName; Drop Table FullName; |
| ||||||||||||||||||||||||||||||||||||||||||
Suppose you have a variable that holds a path name vMyPath, Set vMyPath=\Users\ext_jrb\Documents\Qlik\Sense\Apps;. | In a text & image chart, you can add a measure such as: SubField(vMyPath, '\',-3), which results in 'Qlik', because it is the substring third from the right-hand end of the variable vMyPath. | ||||||||||||||||||||||||||||||||||||||||||
This example shows how using multiple instances of the Subfield() function, each with the field_no parameter left out, from within the same LOADstatement creates Cartesian products of all combinations. The DISTINCT option is used to avoid creating duplicate record. Add the example script to your app and run it. Then add, at least, the fields listed in the results column to a sheet in your app to see the result. LOAD DISTINCT Instrument, SubField(Player,',') as Player, SubField(Project,',') as Project; Load * inline [ Instrument|Player|Project Guitar|Neil,Mike|Music,Video Guitar|Neil|Music,OST Synth|Neil,Jen|Music,Video,OST Synth|Jo|Music Guitar|Neil,Mike|Music,OST ] (delimiter is '|'); |
|
How do I use this syntax if my data has not a delimeter?
Ex: 5F14GZ --> I want to extract 5F1
Thank you
In this case youcan use either MID 0r Left function.
MID('5F14GZ','1','3') =Return 5F1
Left('5F14GZ',3) == 5F1