Hope many of us may struggle to find a solution to split the multiple text value given in a textbox prompt.
Below example may help us to understand the functionality of Macro function "CSV and Split", also it explains how these two macro functions works on filter
to seperate the comma(,) as a seperate value from textbox prompt.
#CSV helps to construct a string from the elements of the array where the values are separated by commas. The default separator is a comma ( , ) and the default quote character is a single quote ( ' ).
Split helps to Split a string or string elements of the array into separate elements
Case1:
Imagine Text Box Prompt has Value as "New York,Florida,Texsas,Washington"
Refer the below code to seperate the comma using filter.
([Data Item to be Filtered]) in (#csv( split(',', prompt('PARAM_Chr_State', 'token')))#)
Above code do not filter correctly if users put spaces between the comma-separated values (ie. "New York, Florida,Texsas, Washington" instead of "New York,Florida,Texsas,Washington")
Case2:
Imagine Text Box Prompt has Value as "New York, Florida,Texsas, Washington"
([Data Item to be Filtered]) in (#csv( split(',', substitute(' ','', prompt('PARAM_Chr_State', 'token')) ) )#)
The substitute expression will remove spaces entered by users between the comma-separated values and filter correctly.
Case3:
Imagine Text Box Prompt has Value as "New York, Florida,Texsas, Washington" or default value is "All".
([Data Item to be Filtered]) in (#csv( split(',', substitute(' ','', prompt('PARAM_Chr_State', 'token')) ) )#)
or 'All' in ?PARAM_Chr_State?
Above filter returns all the rows of data in case no values are entered in the Textbox prompt.
Imp: Above samples works only on string value.
Below example may help us to understand the functionality of Macro function "CSV and Split", also it explains how these two macro functions works on filter
to seperate the comma(,) as a seperate value from textbox prompt.
#CSV helps to construct a string from the elements of the array where the values are separated by commas. The default separator is a comma ( , ) and the default quote character is a single quote ( ' ).
Split helps to Split a string or string elements of the array into separate elements
Case1:
Imagine Text Box Prompt has Value as "New York,Florida,Texsas,Washington"
Refer the below code to seperate the comma using filter.
([Data Item to be Filtered]) in (#csv( split(',', prompt('PARAM_Chr_State', 'token')))#)
Above code do not filter correctly if users put spaces between the comma-separated values (ie. "New York, Florida,Texsas, Washington" instead of "New York,Florida,Texsas,Washington")
Case2:
Imagine Text Box Prompt has Value as "New York, Florida,Texsas, Washington"
([Data Item to be Filtered]) in (#csv( split(',', substitute(' ','', prompt('PARAM_Chr_State', 'token')) ) )#)
The substitute expression will remove spaces entered by users between the comma-separated values and filter correctly.
Case3:
Imagine Text Box Prompt has Value as "New York, Florida,Texsas, Washington" or default value is "All".
([Data Item to be Filtered]) in (#csv( split(',', substitute(' ','', prompt('PARAM_Chr_State', 'token')) ) )#)
or 'All' in ?PARAM_Chr_State?
Above filter returns all the rows of data in case no values are entered in the Textbox prompt.
Imp: Above samples works only on string value.
Hi Sujatha,
ReplyDeleteDo you know if its possible to split a string Data Item by a |, and after that group in the same column?
We work with Cognos Version 8.4.1
Best regards,
Hi Sujatha,
ReplyDeletethanks for sharing the above article. I would like to implement the same for numeric values instead of string values. can you please let me know how to achieve?
Thanks in advance,
Mahesh
Is it possible in Multiselect value prompt. Have been trying..Can you please help.
ReplyDeleteThanks in advance
Shilpa