COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: Cognosnewbie26 on 16 Aug 2021 07:23:56 PM

Title: Modifying the value stored in the parameter passed by a prompt
Post by: Cognosnewbie26 on 16 Aug 2021 07:23:56 PM
Hi,
I have a prompt p_ABC that contains a value like 1234 - WERTY and I want to extract the value '1234' to filter a list report of another datasource and the datasource has the column with only the numbers. Also it's a prompt that can have multiple values. Any help would be greatly appreciated
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: CognosPaul on 19 Aug 2021 10:14:23 AM
Are all of the values going to contain the same pattern?
Take a look at this expression:

#sq(
csv(
substitute('\|','',
grep('\|',
split(' - ',
substitute(' - ','| - ',
split(';',
  promptmany('p_ABC','token')
)))))
)
)#


Pass the following parameters to it:
1234 - WERTY
1235 - ERTYU
1236 - RTYUI

You'll get this output:
'1234','1235','1236'

First around it splits the list of parameters into an array, then on each element in the array it replaces  " - " with "| - ", making it look like:
1234| - WERTY
1235| - ERTYU
1236| - RTYUI

Next it splits on " - " so we'll get the array:
1234|
WERTY
1235|
ERTYU
1236|
RTYUI

Next it greps "|", returning all the elements with the pipe. If the second half of your parameter values might have pipes, you should use a different delimiter.
1234|
1235|
1236|

Next it replaces the pipes with an empty string
1234
1235
1236

The CSV function will return comma separated string:
'1234','1235','1236'

If you just want it as numbers you could use:

#sq(
join(','
substitute('\|','',
grep('\|',
split(' - ',
substitute(' - ','| - ',
split(';',
  promptmany('p_ABC','token')
)))))
)
)#

Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: Cognosnewbie26 on 19 Aug 2021 10:42:38 AM
Thanks @CognosPaul for your response. I am a big fan of your blogs specially the searchable tree prompts that I have implemented in our reports and I have worked with your friend Itzik as well. As my username suggests I just learnt Cognos on my own in the past 9 months.
Initially when I asked the question, I didn't realize that the parameter ( coming from tree prompt) contains the entire hierarchy and I had to look for the lowest level. I am able to do this by using the below piece of code that gets me the values in the format 123,XYZ,345,XYZ ( XYZ is basically the level that is also getting extracted )
#csv(array(substitute(' ','',join(',',split(' - ',substitute(']','',grep(']',split('||',join('||',grep('all',split('->',join('||',split(')',join('||',grep(']',substitute(';','||',substitute('\[','||',substitute(']\.','||',split('].',promptmany('Parameter2', 'memberuniquename','[SG&A Presentation Layer - DMR].[Cost Center Hierarchy].[Cost Center Hierarchy] in (', '', ')'))))))))))))))))))))#

source is :http://cognosandme.blogspot.com/2010/08/single-select-tree-prompt-on-relational.html

The above solution works for a single selection but doesn't work in case of multi selection.

I also tried the below code that gives me data in the format '123','XYZ','345' but it doesn't work at all
#csv(array(substitute(' ','',''''+join(''',''',split(' - ',substitute(']','',grep(']',split('||',join('||',grep('all',split('->',join('||',split(')',join('||',grep(']',substitute(';','||',substitute('\[','||',substitute(']\.','||',split('].',promptmany('Parameter2', 'memberuniquename','rootMembers([SG&A Presentation Layer - DMR].[Cost Center Hierarchy].[Cost Center Hierarchy] in (', '', ')'))))))))))))))))))+''''))#
I would really appreciate your help on this !!!
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: CognosPaul on 20 Aug 2021 02:49:13 AM
I'm really glad that my posts have helped! It's always gratifying to hear things like that.

Can you post an example of the members you're getting? Also, are you expecting the users to select from multiple levels?

Let's say the users select the following

 
  [cube].[dim].[hier].[level1]->[123]
, [cube].[dim].[hier].[level2]->[234]
, [cube].[dim].[hier].[level3]->[345]


Are you expecting the filter at the end to look like this?
[level1] = 123 OR [level2]=234 OR [level3]=345

Or can you get away with just:
[identifier] in (123,234,345)
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: Cognosnewbie26 on 20 Aug 2021 01:18:04 PM
It am just using a single level to filter all those values and that level contains only numbers and so something like (123,345,456) should suffice.
Thanks again for your help
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: CognosPaul on 23 Aug 2021 02:04:25 AM
Can you paste in an example mun? The syntax may be a little different based on the muns your cube generates.
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: Cognosnewbie26 on 24 Aug 2021 11:46:59 AM
Here is what it looks like:
[Cube].[Dimension].[Dimension].[Level 11]->[all].[Level 1].[Level 2].[Level 3].[Level 4].[Level 5].[Level 6].[Level 7].[Level 8].[Level 9].[Level 10]
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: CognosPaul on 30 Aug 2021 05:11:34 AM
Try this:



[data item] in (
#
csv(
substitute('\[','',substitute('\]','',substitute('\|\|','',
grep('\|\|',
split('.',
join('||.',
split(';',

  promptmany('p_ABC','token')

))+'||')))
)))
#
)
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: Cognosnewbie26 on 30 Aug 2021 06:58:34 PM
It did not work for me because it gave me the hierarchy whereas I am looking at the lowest level
Title: Re: Modifying the value stored in the parameter passed by a prompt
Post by: CognosPaul on 31 Aug 2021 04:32:09 AM
Run this, and in the p_ABC prompt paste in the MUNs you're expecting. Then paste the results here.

#sq(
csv(
substitute('\[','',substitute('\]','',substitute('\|\|','',
grep('\|\|',
split('.',
join('||.',
split(';',

  promptmany('p_ABC','token')

))+'||')))
)))
)#