Tuesday 1 January 2013

Cognos - Split Multiple Value in Prompt

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.

4 comments:

  1. Hi Sujatha,

    Do 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,

    ReplyDelete
  2. Hi Sujatha,

    thanks 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

    ReplyDelete
  3. Hello, I am using Select & Search Prompt ('SEL_VAL')in Congos and it gives me 10 values, like (00000- Value1, 000001 - Values2_23256, etc) When I add ParamDisplayValue('SEL_VAL') it gives me the result: all values in a row (00000- Value1, 000001 - Values2_23256) etc... I have a requirement to split it at the ",". for ex:
    00000- Value1,
    000001 - Values2_23256
    etc
    thank you for your help

    ReplyDelete
  4. Is it possible in Multiselect value prompt. Have been trying..Can you please help.
    Thanks in advance
    Shilpa

    ReplyDelete