Friday, April 18, 2008

prompts explained

Prompts provide a way to dynamically change the reports.

In other words their function is to "show only this", "show only that', "show between this day and that day".

I think it would be fair to say that a prompt is what appears on the screen and a parameter is a programming variable that stores the users choice.

So prompts and parameters are very closely related, they are practically the same.

A prompt appears minimum in two places. On the prompt page - where we get the value - and in an expression - where we use the value. (Otherwise it would not make sense...)
If a prompt appears in an expression but you forgot to put it on the prompt page then it will be autogenerated by Cognos. You don't want this... it's much better to have control over the prompt page.

However it can appear in more than two places as it gets used in expressions and even in the model. 
If you use DMR it is a good idea to use prompts in the model because you can optimize the performance. e.g. If the user selects only a single branch of a bank then there is no need to calculate all metrics for every branch, you can use the prompt in the model to set a filter on the queries... and everything will run faster.

There are a few important things about prompts that are not obvious from the documentation:

  1. In Report Studio you can use the same #prompt()# function as in Framework Manager. (Actually you can use all macro functions.) 
    What you see - what the editor offers - ?Parameter1? is just a shorthand for #prompt('Parameter1', 'string')#
  2. You need to refer to prompts in exactly the same way everywhere, in expressions and on the prompt page. Otherwise Cognos gets confused. Thisnk about this when you set a prompt as "required" but its not, or when the prompt pop up again even though it already appeared on the prompt page.
    The property settings should match how the #prompt()# macro is called. 
  3. For a prompt being optional is the same thing as having default value. 
    If a prompt has default value then it is optional.
    If a prompt is optional it must have a default value. 

    The only exception is to set the default selection property in Report Studio and set the prompt as required; and then in the expressions not setting a default value. This way the prompt is required and the prompt page can provide the value set as default if you hide the prompt. - This technique allows you to do some tricks...
  4. Remember: prompt is a macro. It is just a string replacement. Whatever appears between the hashmarks will be replaced and then the expression will be evaluated.
    If you get an error you can usually see what the prompt macro was replaced with.
    You can also debug the report by droppin a Text Item, setting its source to "Report Expression" and setting the expression to something like ParamValue('parameter1')
    - do not use ParamDisplayValue() .. use ParamValue()
  5. Since the prompts will be used in different expressions you get most freedom by setting the prompt type to "token". This way the replacement value won't have quotation marks around it. This is useful. Check the other macro functions such as split(), sq() to build a string from the prompt as needed.
  6. Keep in mind the promptmany() function. It is practically the multi-selection prompt.
    If you want the prompt to handle multiple values then you need to use this version. 

Working with prompts using a dimensional model

The prompt can return the parameter value in a number of ways: string, date, token, MUN (Member Unique Name).

If you don't know what MUN is please read the documentation; it is important. It's basically a string identifier for a member of a dimension. It's an ID... plus some extra that helps to figue out what the ID is for. 

When working with dimensional model you want to build a member set from the prompt selection... pretty much always. 
If you think you only need to build a filter expression please think twice.
For a DMR model I'm pretty sure filters should not be used - at all.
and I have the same feeling for an OLAP based dimensional model.
So, forget filters. They are for the people still in the kindergarden who use relational models for BI.
All you want to do is to say which members should appear in a crosstab (or chart) based on the users selection. What you need is a member set.

To build a member set the "string" type of prompt is useless because it is surrounded by single quotes which does not play well with the MUN (Member Unique Name) format.
Either you can get the MUN directly from the prompt() function or you need to build it yourself. In this case "token" is better. It's the same value being returned as when using "string" only without the quotes.

I find that using the question mark shorthand: ?Parameter1? is the same as #prompt('Parameter1', 'string')#
Frankly I'm not 100% sure... but I still prefer using the macro format to be certain of what I'll get.

The easiest thing to build a memberset is to do this:
set( #promptmany('Parameter1', 'MUN' )# )
It gets challenging when you want to make the prompt optional.
If you only return an empty string or a space then after the prompt is processed the expression will look like set( ) ... which Cognos does not like and gives you an error.
Instead use the emptySet function as the prompt's default valuet:
set( #promptmany('OptionalParameter1', 'MUN', emptySet([my_dimension].[my_hierarchy])# )
To have the prompt return MUN you need to set the "Use Value" of its query to a dimension level.

The other option is to build the MUn yourself in the expression. If the MUN has only one ID then it's simple. Something like 
[my_dimension].[my_hierarchy].[my_level]->[all].#sq(prompt('parameter1','token'))#

With DMR model it is often not the case... even if you set a level as "Uniquely Identified" Cognos still includes the business keys of all upper levels in the MUN... which makes it difficult - almost impossible - to build MUNs.
(I think it is a bug in Cognos DMR.)
You can only do it if you prompt the dimension members themselves. then Cognos will do it.
Otherwise... not.
e.g. If you have a hierarchy in the time dimension it can become difficult. Because you want a date prompt - which is not built from the dimension. It's just a calendar.
That's OK... you don't want to use DMR anyways. It sucks. Use real OLAP and take control of how the MUNs are generated.

I figured that with the promptmany function using tokens they are separated by semicolons.
start with #split(';', promptmany('Parameter1', 'token'))# and use the substitute macro to build a lst of MUNs.

Time filtering: From and To

Often you want to run the report for a specified time interval. this is not at easy as it seams.
If you find that a simple filter is not working for you.. and remember, IMO you should never use a filter... then you'll appreciate this tip as building a member set containing all dates between "from" and "to" gets quite challenging.
filter(
[Time Dimension].[My Hierarchy].[Date],
roleValue('_businessKey', currentMember([Time Dimension].[My Hierarchy])) >= #sq(prompt('From', 'Date'))# and 
roleValue('_businessKey', currentMember([Time Dimension].[My Hierarchy])) <= #sq(prompt('To', 'Date'))#

)

i know it's crazy... but this will save you 2 days minimum.
  • we're using the filter() function to "build" the member set - by taking away unwanted members.
  • we rely on the fact that dates as string can be still compared and will maintain the same order as the dates
  • note that roleValue() returns the selected attribute as a string, regardless of the attribute's type - which is date in this example
I'll write a post about why filtering should be avoided... so hopefully I'll convince you that I'm not crazy and all this overcomplicated crap is necessary for real life reporting... I mean something other than GO Sales :)


68 comments:

  1. Hi,

    I want to use date filters for my report based on dimensional model.Date is not a part of my list. How do i use the time range filtering technique that you have proposed in this blog? I tried to create a data item using the mentioned expression and then put it as a slicer set,but that is giving error.

    Can you please suggest something in this regard?

    ReplyDelete
  2. There is a slight error on this page. The promptmany command should have the third parameter in quotes:-

    set( #promptmany('OptionalParameter1', 'MUN', 'emptySet([my_dimension].[my_hierarchy])'# )

    ReplyDelete
  3. We tried these techniques to implement an optional MDX (Powerplay cube) date filter. When the user does not choose a month the report defaults to the current month.

    In C8.2 the DefaultValue of the prompt does not accept an MDX function and is therefore useless.

    1) Create an optional prompt on the month level of the date dimension
    2) Create the cross tab using the required axis (date is not part of the crosstab). The measure is the required measure.
    3) Create a Query dataitem named currentMonth which reference the Transformer currentMonth special category
    4) Create a data item called month which is:
    promptmany('OptionalParameter1', 'MUN', 'firstSibling(currentMonth)'#
    5) Change the measure to tuple ( measure, month ) to filter by the chosen month

    ReplyDelete
  4. Hi Alex

    I don't think the prompt macro "cares" about the default value... it just passes it on as a string.
    So if you had problems with it then it must be because of the resulting expression being invalid.

    ReplyDelete
  5. Hi,
    I am creating a calculation in FM using
    prompt and promptmany macro function in
    DMR model and I want to used this calculation
    in report studio for dynamic column selection in crosstab I tried your method

    code fragment I am using in calculation is like that
    set(#promptmany('msr_param','MUN','item(emptySet(
    [Dim Layer].[sales fact].[QUANTITY]),0)')#)

    It gives an error coercion of measure heirarchy to level

    I also put a single qoute as suggested by Alex in 3rd argument .

    This calculation I want to use as Measure Column
    in crosstab in report studio to be selected by user using value prompt.

    ReplyDelete
  6. Can you come up with more suggestion on Prompt,
    parameter maps ,promptmany with DMR model

    What all things we need to keep in mind when
    we make a Dimensional report in Report Studio.
    using prompt & macros.

    Is there any Issue's using Slicer with prompt ?

    ReplyDelete
  7. Hi Jimmy

    looks like the problem in the code snippet is that in the emptySet() you use QUANTITY which is a measure. You need to use the same diemsnion that the msr_param is.

    Here is the thinking:
    Do you want this prompt to be mandatory or optional?
    If it's optional then it must have a default value.
    What should be the default value?
    In other words: what should be the default selection when the user does not select anything?
    Should it be "nothing"?
    If so... the Cognos way to say "nothing" is a bit cumbersome...
    you need an empty set of the given dimension and then you take the first (zeroth) element of that set - because at the end of the whole exercise you are trying to specify an element that goes to the set()
    It's syuntactic nightmare ;-)

    I hope it helps you.
    Please post specific questions, and I'll try to answer them.

    ReplyDelete
  8. Hi Tamas,

    Thanks for the reply, Actually I am
    doing DMR reporting for the first time I was not aware of the Dimensional function's & I have never used it before, I did go through some Dim. Func. pdf to know about it.

    If you can Please provide some more Information on prompt, parameter map and macros.

    thanks

    ReplyDelete
  9. Just read the rest of the articles :)

    ReplyDelete
  10. Hi Tamas,

    Can you shed some light on MDX queries in report
    studio, how to write it and how to approach towards it using dimensional function with example using Go sales & retailer package as this is the topic which is least discuss in any of the cognos forums and for some cognos consultant it still an enigma :).

    Thanks

    ReplyDelete
  11. Hi Jimmy

    I have already written a lot about this in previous posts.

    Briefly speaking you don't write MDX directly. cognos takes care of that.
    Instead you create queries where every data item is a dimensional expression. So these "queries" are not really queries in the relational way.

    Also, forget lists. Use only crosstabs and charts when working with dimensional data source.

    Check out my posts about crosstabs, charts (how they work the same as crosstabs)
    and tuple and memberset expressions.

    You can also ask concrete questions with details... the geenral articles are already out there.

    ReplyDelete
  12. Hi Tamas,

    Any Idea about the dynamic subtotal in relational report like subtotal on prodtype column value 'lanterns' 'Irons' and 'Packs' not on the others prod type but other product type value should be shown, within crosstab nested with prod line and subtotal on prodname column on only few selected prodname.

    I have had acheived the desired result in DMR reports ,but bit clueless as we cannot se the level and member in the relationl approach

    Thanks

    Jimmy

    ReplyDelete
  13. Hey Tamas,

    Its done now :) I used conditional variable with boolean exprn & used that in data item of subtotal.

    Thanks

    ReplyDelete
  14. #promptmany('msr_param','token','[Revenue]')#

    Its a Relational Data, when I validate this in report studio it says no error I'm using this as a column in to select it from Value prompt.
    But after selecting it from value value prompt
    & when I run it gives me an parsing error

    QE-DEF-0260 parsing error [Revenue]";"

    Am I doin something wrong ?

    In DMR we can achieve the same thing with the syntax Its work fine

    #'set(' + promptmany('Msr_Param','token','[Revenue]') + ')'#

    How to go about it when we have Relational data

    ReplyDelete
  15. Hi This is a GREAT Site. Wonderful Stuff.I have a PROBLEM please help. I have a report with cube as source and used the expression set(#promptmany('Measures','token')#),into DATA ITEM, to select multiple Measures from the prompt page into crosstab and it works GREAT. Now i need to drill through from those Measures to a Target Report(same cube source) which i am not able to get. For example if I click on a Particular Single Measure and Drill Through I need to see the information of that particular measure only. Any Help Greatly Appreciated.

    Many Thanks.

    ReplyDelete
  16. I haven't done many drill-through report... in my testing drilling-through it's much like setting one of the prompt values via linking... so I guess just make sure you're passing in the right values.

    ReplyDelete
  17. Thanks for your Reply. I really appreciate your help. Passing the right values worked. Thanks Again.

    ReplyDelete
  18. I have a situation where I have to build a management report over 8 different cubes. They have 3 shared dimensions, but the members do not have the same category code. I want to apply one prompt to filter all of the queries over the separate cubes.

    I have a period filter and need to make a ytd calculation. For this I use;

    aggregate(tuple([Category];[Amount]) within set periodstodate([xxxx].[Period].[Period].[Year];item(filter([xxxx].[Period].[Period].[Month]; caption([xxxx].[Period].[Period].[Month])=?p_Periode?);0)))

    This works fine. I use the caption to avoid problems with the first part if the MUN wich indicates the cube name.

    Now i want to filter the Organisation dimension using a slicer in the query. I want to make the slicer optional. The slicer I now Use is like;

    set(item(filter([xxxx].[D_Organisation].[D_Organisation].[FunctionGroup];caption([xxxx].[D_Organisation].[D_Organisation].[FunctionGroup])=?p_Organisatie?);0))

    This works, but it is not optional. I can use a promptfunction with a default value, and the defaultvalue works fine, but i cant get the macro function to return the membercaption of the member returned by the prompt.

    Any Ideas?

    ReplyDelete
  19. solved issue above bij using

    #Prompt('p_Organisatie','Token', '[Default Slicer Organisatie]', 'set(item(filter([xxxx].[D_Organisation].[D_Organisation].[Functiongroup];caption([xxxx].[D_Organisation].[D_Organisation].[Functiongroup])=','[Space]',');0))')#

    Where [Default Slicer Organisatie] = Rootmemebers([xxxx].[D_Organisation].[D_Organisation])
    And [Space] = ''

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. Hi Frank/any1,

    I am trying to set filtering between multiple reports (different tabs in a dashboard) and each report comes from a different cube. Each report will have some common prompts and several different ones. For e.g. an account value prompt may be created in 1 report but not in another. Have you guys tried before? Frank, I used your method of caption and it works for the common filters. But the uncommon ones do not work and do not even go to the default selection.

    Can any1 please help me?
    Many thanks!

    ReplyDelete
  22. Hi Tamas,
    Hope you can help me with my problem:

    I have three prompts

    The first 2 prompts are required and the third is based on the entry on the first prompt. The third prompt is also hidden/shown conditionally.

    For instance, if the first prompt has a value of 'A' the third prompt will be set to being 'required' and will be displayed otherwise it will be set to being 'optional' and hidden.

    Hiding and unhiding the prompt is easy, but i got a problem setting the usage the third prompt conditionally.

    How can I do this?

    ReplyDelete
  23. Hi...
    I am a cognos starter.. trying to create hierarchies.. got this error..while publishing a package

    "BMT-MD-6006 The package contains orphan dimensions that are not in scope with other measure or regular dimensions. Queries that reference regular and measure dimensions that are not associated with a scope relationship may not run."..

    No idea how to resolve this. a deeper example for setting up hierarchies would help a lot

    ReplyDelete
  24. chandrashekar, basically you created a dimension that is not used.
    it can be similar to this:
    you are _measuring_ the number of sales with two measures: sum of $ and count of sales
    so you can report on sum and average
    Your dimnsions are product category, time and location (which branch/franchise made the sale)

    BUT...

    You forget to hook up the product dimension

    So your dimensional model can only report on sales per day/month/year and per location

    Even though you do have a product dimension it is an "orphaned dimension"
    It is created... meaning you can see the products categorized into levels of a hierarchy,
    but it is not used
    because the query to calculate you two measures does not break the count of sales or sum of $ down to how many was sold per product category.

    The intersection of all dimensions should give you the smallest granularity your dimensional model aka "cube" should have... and you need to construct your queries aka fact tables accordingly

    I hope this helps!

    ReplyDelete
  25. Hi,
    I have a situation where I need to have a prompt for Month Period and at the same time column calculation of MTD and YTD of netsales and gross sales as measures. with a rows of product. Can someone provide me a calculation for YTD and MTD. I am using OLAP CUBE/Dimensional model as source for reporting.
    Thanks..
    Alex

    ReplyDelete
  26. Hi,

    I want to build the MUN for yesterday's date from current_date function. How can I do this? I am getting string parsing error when I try to use #sb()# macro function with current_date cognos function. Can someone please help?

    Thanks.
    Sriram.

    ReplyDelete
  27. I'd build the MUN using #sb() and other functions anf then use prevMember

    Have a look at how an MUN looks in your time dimension and try to construct that from whatever string you get back from the prompt.
    You may need to use #substitute() to replace dashes (``-'') or slashes (``/'') depending on what date format the prompt returns vs what date format is used in the MUN.

    I hope this helps, if not please post more details...

    ReplyDelete
  28. Hi, I wonder of any of you can assist me.

    I am NOT well-versed with MDX and have to report off a TM1 cube (cube cannot be changed to "best practices" as recommended by IBM due to practical reasons). In TM1, there is a concept of parallel hierarchies. Unfortunately, only 1 hierarchy can be defined in any TM1 cube, so this is a feature that is not working properly as all parallel hierarchies do not have the same structure.

    My problem is this: there are multiple cubes that have been published that all relate to the same data, albeit at different levels. I am trying to pass a parameter to all the different cubes, but cannot use the MUN because the path for the same member is different, even though the businesskey is the same:

    i.e.

    All Years, 2010

    in different cubes come through as cube name\dimension\All Years etc

    I can filter using the businesskey, but the value "2010" occurs in multiple hierarchies, so the values are duplicated for every occurence of the value "2010" in the cube.

    Is there any way that I can force the filter to read from a specific member to force the cube to be filtered in the appropriate hierarchy.

    Alternatively, is there a way I can bring back the parent and filter on parent and child for the selected value.

    As I said, my MDX is inadequate.

    Great site!

    ReplyDelete
  29. Hi Sandy

    yes there is a way to do it -if I understand you correctly...
    your two (or more) cubes have different MUN structure and you only have one parameter (coming from a prompt)... so you need to pick one of the two dimensional hierarchies to be used for prompting.
    Remeber: what the prompt returns is just a string.
    I think what you need to do is "massage" this string until you change it from one MUN format to the other.
    the #prompt()# is a macro function. Wrap it with other macro functions, like sb() and substitute()

    if you send here the details of how the two MUNs structures look then I can help you create the right expression

    ReplyDelete
  30. Hi all, It seems as a lot of Gurus here. I am new to MDX. I am using Cognos connecting to SSAS cube. I need a prompt that uses calender date to be able to pick specific dates(not a date range) to report. How do I do this?

    ReplyDelete
  31. how about one at a time?
    I don't think that Cognos lets you build a list of dates... so your only other option is to say something like you have max 10 dates to pick and then add 10 optional date prompts

    ReplyDelete
  32. I am good with whatever the number of dates to pick. I think they expect about 5 at a time. So a calender prompt to choose dates and then to show them as columns. Right now I got it be working as Value prompt but need a calender. Thanks for the quick response.
    Currently I have the following(Copied from your site:-)) works good but only as a value prompt.
    #promptmany('Date', 'memberuniquename', '[Financials].[Posting Date].[Posting Date.Calendar Time].[Date]', 'set(', '[Financials].[Posting Date].[Posting Date.Calendar Time].[Date]', ')')#

    ReplyDelete
  33. Hi, just the fact that you understand my problem is already a huge plus.

    The MUNs are:
    [CIB IT RtB External Expenses].[CIB_IT_Catalogue].[CIB_IT_Catalogue]->:[TM].[CIB_IT_Catalogue].[CIB_IT_Catalogue].[@MEMBER].[0000023157^11730258]
    [CIB IT RtB Infrastructure].[CIB_IT_Catalogue].[CIB_IT_Catalogue]->:[TM].[CIB_IT_Catalogue].[CIB_IT_Catalogue].[@MEMBER].[0000023157^11730258]
    Where "11730258" is an application, and "0000023157" is a cost centre. Both of these are prompted for where I'm cascading the application based on the cost centre.

    Your help is really appreciated.

    ReplyDelete
  34. Hi Sandy...

    Are you using a tree prompt?
    Is it based on one of these two dimensions?

    Let's assume it's based on the first one...
    then you need to do something like this:
    #substitute(
    '[CIB IT RtB External Expenses].[CIB_IT_Catalogue].[CIB_IT_Catalogue]->:[TM].[CIB_IT_Catalogue].[CIB_IT_Catalogue].[@MEMBER].',
    '[CIB IT RtB Infrastructure].[CIB_IT_Catalogue].[CIB_IT_Catalogue]->:[TM].[CIB_IT_Catalogue].[CIB_IT_Catalogue].[@MEMBER].',
    prompt(...))#

    the point is that the #prompt()# will return you the MUN as a string and you need to mess around with that string until you transform it the way you want it.
    There are some undocumented features I found, like being able to match the beginning and end of a string with substitute...
    See here:
    http://unofficialcognostraining.blogspot.com/2008/04/substitute-macro.html

    You can nest it.... so you can write
    #substitute('this','with that', substitute('something else', 'with yet another thing', original_string))#

    It's ugly but it works ;-)

    ps. CIB... wow! can I get a low rate mortgage :-)

    ReplyDelete
  35. That1matt

    you can use date prompt...
    it will probably return you the date in a format like ``2010-08-26''
    or ``2010/08/26''

    ...and you go from here.
    you probably need to get it into a format something like this:
    [My_Cube].[Time Dimension].[YMD Hieararchy]->:[@MEMBER].[20100826]

    so you need to play with the macro functions until you get the transformation you got. (See my reply above)
    You probably need to use
    #substitute()# to replace the dashes or slashes
    #sb()# to add square brackets around the value
    #substitute('$' or substitute('^' to prefix or append to it

    ...and make the whole thing a set()

    I hope this helps...

    ReplyDelete
  36. wow! This site is amazing!! Such quick responses!!! Thank you Tamas. It does help. However since I am new, it would be nice if I can have a sample. I understand this needs to be based on how the MUN is built. But whatever the sample(if you already have one) you give me, I should be able to modify and work from there. Thanks again...

    ReplyDelete
  37. Sorry, I just read above the rest. You already have put something out there. I will try from what is there. Thanks.

    ReplyDelete
  38. I looked at it and I am not sure where do I start. This is what Date MUN looks like,
    [Financials].[Posting Date].[Posting Date.Calendar Time].[Date]->:[M8].[[Posting Date]].[Calendar Time]].[Calendar Year]].&[2000]].&[Q1 00]].&[Jan 00]].&[2000-01-01T00:00:00]]]
    What do I need to do now?

    ReplyDelete
  39. Hi All, I'm having a problem with the "Time filtering: From and To" code. Presently Cognos support doesn't have any ideas & we only got this far due to your blog which I found recently (THANK YOU!). It does work for our data except that whatever date is specified as the “From” date is excluded from the result set. It’s as if the >= in the filter is replaced with >. For example, if I select aug 1- aug 31 the 1st is excluded. If I select aug 1-aug 1 there is no data. Aug 1 – aug 2 gives data for aug 2 only.

    Code:
    filter([Time Dimension].[My Hierarchy].[Year-Month-Day],
    roleValue('_businessKey', [Time Dimension].[My Hierarchy].[Year-Month-Day]) >= #sq(prompt('From', 'Date'))# and
    roleValue('_businessKey', [Time Dimension].[My Hierarchy].[Year-Month-Day]) <= #sq(prompt('To', 'Date'))#)

    Oddly even when I remove the first & use an or statement to pick it up the result is the same so it seems as if the issue may be in the filter rather than internal logic:

    filter([Time Dimension].[My Hierarchy].[Year-Month-Day], roleValue('_businessKey', [Time Dimension].[My Hierarchy].[Year-Month-Day]) = #sq(prompt('From', 'Date'))# or
    (roleValue('_businessKey', [Time Dimension].[My Hierarchy].[Year-Month-Day]) > #sq(prompt('From', 'Date'))# and
    roleValue('_businessKey', [Time Dimension].[My Hierarchy].[Year-Month-Day]) <= #sq(prompt('To', 'Date'))#))

    Note that for Cognos 8.4.1 the "currentMember" part is optional and i get the same result regardless of whether or not its included.

    No it doesn't matter which days I choose (meaning which month, overlapping months, etc). Yes attaching an excel pivot table to the MSAS cube works. Yes other date things in Cognos 8 work.

    Any help would be greatly appreciated. Thank you.

    ReplyDelete
  40. Problem solved:
    I was able to get the filter to work properly by switching away from a dimension as [year-month-day] to [YYYYMMDD] then modifying the result from the date prompt to match as follows:

    filter(
    [Time Dimension].[My Hierarchy].[Date ID],
    roleValue('_businessKey', [Time Dimension].[My Hierarchy].[Date ID]) >= #substitute('-','',substitute('-','',sq(prompt('StartDate', 'Date'))))# and
    roleValue('_businessKey', [Time Dimension].[My Hierarchy].[Date ID]) <= #substitute('-','',substitute('-','',sq(prompt('EndDate', 'Date'))))#)

    Note sq() add's square brackets, substitute(,,) well, substitutes things. It was needed twice for removing both "-"'s because the function only replaces the first one found. Also, specifying '_businessKey' in the RoleValue is necessary - you can't replace that with something else. Review the RoleValue function if needed.

    Thanks.

    ReplyDelete
  41. I'm glad it's resolved.
    Keep the comments coming, it's very precious stuff :)

    ReplyDelete
  42. Hi everybody,
    I try to create a prompt page that can run my query. For example, my report has 3 different queries and on my prompt page I want to have a drop down menu or a radio button that list all my queries for the user to choose and run that query only.

    Thanks,

    Thanh

    ReplyDelete
  43. Do you know the limitations for a token prompt:
    for example #prompt('String','token', '0')# in the Framework, what is the maximum size of the String I can use(the String in my case is an expression made up of FW query items)

    ReplyDelete
  44. Here is the problem I have. I am trying to pass a parameter in event studio to schedule a report. This parameter is previous fiscal year. Note, this parameter needs to accept the MUN like [Time Dimension].[My Hierarchy].[Year].[All].[YYYY]. I need to build a MUN using the current date function with help of macro. How do I use a current_date function to build the MUN. If I am able to use a calculated data item in macro containing the prev year exp in string format would also suffice.

    ReplyDelete
  45. Ran into an issue on Cognos10.1; don't do this:

    set( #promptmany('Parameter1', 'MUN','[dataitem]')# )

    instead do this:-

    #promptmany( 'Parameter1', 'MUN','[dataitem]', 'set(','',')' )

    That works in more cases than wrapping the set() function around the macro. Seems like something subtle changed between C8.2 and C10.1

    ReplyDelete
  46. Hi all
    there is much valuable information on this site but i am having an issue with this.

    is there anyway i can make this an optional prompt slicer

    filter(
    [Farmington APD Scorecard].[Activity Dt].[Activity Dt].[Day],
    roleValue('_businessKey', currentMember([Farmington APD Scorecard].[Activity Dt].[Activity Dt])) >= # substitute('-','',substitute('-','',sq(prompt('StartDate', 'Date'))))# and
    roleValue('_businessKey', currentMember([Farmington APD Scorecard].[Activity Dt].[Activity Dt])) <= # substitute('-','',substitute('-','',sq(prompt('EndDate', 'Date'))))#)

    ReplyDelete
  47. Hi "DealSeeker"

    to make the prompt in your example optional it must have a default value.
    so instead of #prompt('StartDate', 'Date') format you need to use something like #prompt('StartDate', 'Date', default_value)

    You may have to find a smart trick to come up with good default values to fall back to... that work as if no filter is specified.

    ReplyDelete
  48. Hi All,
    The following macro is failing could you please help me in resolving the single quotes in pretext.

    #promptmany(‘QuoteMethod’,
    ‘varchar(500)’,
    ‘ ‘,
    ‘ AND (Case When Quote_Assess.QUOTE_COUNT=1 Then ‘Single Quote’ Else ‘Competitive Quote’ End) IN (‘, ”, ‘)’
    )#

    Thanks

    ReplyDelete
  49. Hi,

    I have a data item in my report which needs to be a differente level of the same hierarchy conditioned by the value of another data item which contains a prompt.

    Please advise.

    Thanks

    Charles

    ReplyDelete
  50. .....

    In the condition I have tried using ParamValue(), roleValue('_memberUniqueName', and also referncing the prompt directly ?Prompt?, but it all is rejected.

    Thanks again

    ReplyDelete
  51. If u use this:
    filter(
    [Time Dimension].[My Hierarchy].[Date],
    roleValue('_businessKey', currentMember([Time Dimension].[My Hierarchy])) >= #sq(prompt('From', 'Date'))# and
    roleValue('_businessKey', currentMember([Time Dimension].[My Hierarchy])) <= #sq(prompt('To', 'Date'))#
    )

    Can i just add date prompts to the prompt page?
    And where do i put this expression?
    Do i put it in the slicer?

    Thx

    ReplyDelete
  52. Hi, good day to you all.
    Im just wondering if u guys can help me with my very first project in cognos.

    I have a TEXT BOX Prompt that the range property is set to YES, which will display 2 text box for the inrange value. My question is how do I get the value of the 1st textbox separated from the 2nd text box. because when i use paramValue('TextBox') the value be shown as "value1 to value2". I hope to get only value1.

    Any help and insight will do.. thanks.

    ReplyDelete
  53. Hi,
    First of all thanks a lot for all the knowledge sharing.Iam a beginner in cognos and was trying to do the following.
    Build a tree prompt out of a regular dimension and filter against a relational source.I followed this link http://www.ibm.com/developerworks/data/library/cognos/page310.html
    and got it to work .
    My Problem is that iam not able to make it to work for Multiselect option.So in short iam trying to implement a Multiselect Tree prompt using a regular dimension and filter against a relational source.
    Any help is really appreciated.Thanks a lot.

    ReplyDelete
    Replies
    1. Hi Sriram, I am also having the same issue, I am able to work it for single select but not for multi select, did you find a way to relsolve this, pls let me also know if you got this done.

      thanks
      Veera

      Delete
  54. Anyone ever dynamically change conditional thresholds using text prompt boxes? i.e. a text prompt for high , med, low where the value entered at runtime would define say red yellow and green highlight. Logically I would think this could be done passing the parameter from the prompt to a conditional variable but having a bit of a block on how to set this up. here is what I tried: IF ([Report Query].[Revenue] >[Report Query].[High]) then (?High?)
    ELSE IF ([Report Query].[Revenue] >[Report Query].[Med]) then (?Med?)
    ELSE IF ([Report Query].[Revenue] > [Report Query].[Low]) then (?Low?)
    ELSE ([Report Query].[Revenue])

    but get error: RSV-VAL-0002 Invalid expression [Report Query].[Revenue]>[Report Query].[Low]. CRX-API-0003 A data type error ocurred at or near the position '24' in expression: '[Report Query].[Revenue]>[Report Query].[Low] '. The operand types ('number (quadword),string (varchar)') for operator '>' are not compatible.

    ReplyDelete
  55. ok figured this out shortly after I posted, I moved the parameter ?High? into a new query data item and set the values in the Threshold variable to 'High' , 'Med', 'Low' then corrected the data type mismatch which was giving me the evaluation error by wrapping my expression in [Report Query].[High] to look like cast(?High?, INTEGER). and it worked as expected.

    ReplyDelete
  56. hi, i want to connect crosstab to graph.When i press the different rows of crosstab i should get a graph i want along with it can anyone suggest a method to use prompt and achieve the above mentioned functionality.

    ReplyDelete
  57. Dear friends,
    The PeriodsToDate function im DMR really works? Someone has an example? I need it in the Cognos Express to calculate YTD.
    Regards,
    Pedro

    ReplyDelete
  58. Hello All,

    I'm trying to create a crosstab report with different measure as columns. I want several of those measure to prompt the user for the date value and other columns to default to a date base on the prompts that were selected in the other columns. Any examples out there or suggestions?

    ReplyDelete
  59. Hi ,

    I have a checkbox prompt with parameter 'SVC' and static choice value is 0.
    I have data items in report studio like [Func Revenue],[Service Charge] and when i use macros as shown in [Total]= [Func Revenue]+[Service Charge] * #prompt ('SVC','integer','1')# on prompt page it is changing automatically into radio button. But my requirement is it should be checkbox when i execute the report.

    Please suggest any idea for solving this issue.

    Thanks,
    Sai.

    ReplyDelete
  60. I have crosstab report using dynamic cube.
    This report has 5 optional param.
    I need to calculate totals for visible (filtered) cells using Tuple function
    How to lock the members (filtered) in calculation of Totals using Tuple function??

    ReplyDelete
  61. all optional prompts are macro prompts using
    #promptmany( 'Parameter1', 'MUN','[dataitem]', 'set(','',')' )

    ReplyDelete
  62. I have text box prompt that has vlues e.g 2365434,M597201. when i try to feed values to the promomot while run time it requires bracket [] e. [M597201].i dont want to use bracket can we avoid that.please help

    ReplyDelete
  63. Can we use nested case statements in macros?
    I tried as below but not working in native sql in cognos report studio.

    select * from table where date='14-09-02' and
    #CASE promptmany('IncAdj','string',' ','IND ')
    WHEN ' ' THEN
    '( CASE promptmany'+'('+sq('onlyadj')+','+sq('string')+','+sq(' ')+','+sq('IND ')+')'+
    'WHEN'+sq( ' ')+
    'THEN'+ ' AND ( IND IS NULL OR IND' + '<>'+ sq('Y') + ')' +
    'ELSE ' +'AND'+'('+' IND'+ '='+ sq('Y') +')'+
    ' END'+
    ')'
    ELSE ' '
    END #

    Requirement is as :
    There are two checkbox prompts in prompt page named as P1(IncAdj parameter in above macro) and P2(onlyadj parameter in above macro) and they are optional.
    [P1 and P2 are mutually exclusive but both can be unchecked]
    If P2 unchecked and P1 unchecked
    AND ( IND IS NULL OR IND <> 'Y' )
    { for example when P2 uncheck and P1 un check generated sql query should be: select * from table where date ='14-09-09' and ( IND IS NULL OR IND <> 'Y' )}
    If P1 unchecked and P2 checked
    AND ( IND = 'Y' )
    If P1 checked and P2 unchecked

    ReplyDelete
  64. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in IBM Cognos Transformer Design OLAP Models (v10.2.2) - SPVC (J2A82G-SPVC)
    , kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on in IBM Cognos Transformer Design OLAP Models (v10.2.2) - SPVC (J2A82G-SPVC). We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com


    ReplyDelete
  65. Thank you for sharing this useful information with us.
    Please notify us like this :
    hotmail email

    ReplyDelete