Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
  • 1.  Report with 2 date prompts

    Posted Wed February 22, 2023 09:32 AM

    Hi
    I am trying to create a report (Cognos 11.2.2) with 2 different from-to date prompts on the prompt page.
    The date prompts are optional and must be used seperate.
    How can I default uncheck the checkbox on the date prompt?



    ------------------------------
    Krista Thijsbaert
    ------------------------------



  • 2.  RE: Report with 2 date prompts

    Posted Wed February 22, 2023 09:58 AM

    Hi Krista,

    There are 2 ways.
    1: If the filter expression looks like   [some_date_column] >= ?start_date? and [some_date_column] <= ?end_date? then look in the properties of the filter and set usage->optional.
    2: use the macro function prompt and provide a default value as in:
    [some_date_column] >= #prompt('start_date', 'date', '2006-01-01')# and [some_date_column]  < #prompt('end_date', 'date', '2008-01-01')

    You probably already had a look at: Adding Prompts to Filter Data - IBM Documentation



    ------------------------------
    Kind regards,
    Henk Cazemier
    ------------------------------



  • 3.  RE: Report with 2 date prompts

    Posted Thu February 23, 2023 02:59 AM
      |   view attached

    Henk
    Thanks for your feedback.

    I think that my question is not that clear ;-)

    What I want is to unselect the select box by default (like in the 2nd prompt on the attachment).




    ------------------------------
    Krista Thijsbaert
    ------------------------------



  • 4.  RE: Report with 2 date prompts

    Posted Thu February 23, 2023 09:17 AM

    Hi Krista,

    Sorry, I missed that part. 
    I don't know how to have that checkbox un-checked by default. 
    The only alternative that I can come up with is to make it a mandatory filter with a high default value, which in essence makes the filter not do anything. Then it looks like:



    ------------------------------
    Kind regards,
    Henk Cazemier
    ------------------------------



  • 5.  RE: Report with 2 date prompts

    Posted Thu February 23, 2023 09:29 AM
    Edited by Krista Thijsbaert Thu February 23, 2023 09:31 AM
      |   view attached

    Hi Henk
    No problem.
    I found a workaround: the first prompt is a value prompt with static choices in which you can choose which prompt you want to use. The 2nd prompt is placed in a condtional block and shows the optional date prompts. 
    And the filter in the query is like
    (?PA_Periode? = 'PeriodeX' 
    AND 
    AA.[Datum Begin] <= ?PA_Begindatum? 
    AND 
    (AA[Datum Einde] >= ?PA_Einddatum?)  
    OR 
    (?PA_Periode? = 'PeriodeY' 
    AND 
    BB[Datum Begin] >= ?PA_Begindatum? 
    AND 
    BB.[Datum Einde] <= ?PA_Einddatum?) "



    ------------------------------
    Krista Thijsbaert
    ------------------------------



  • 6.  RE: Report with 2 date prompts

    Posted Thu February 23, 2023 10:04 AM
    Edited by Philipp Hornung Thu February 23, 2023 10:04 AM

    Hi, Maybe it's possible to use a custom control/JavaScript to achieve the desired. I doubt there is direct way to remove the default check mark. You said you need to separate the two parameters/prompts but an in_range date parameter would set the default to "earliest to latest date". Another alternative is to replace the calendar prompt by a dropdown-list prompt of text formatted date values. 



    ------------------------------
    Philipp Hornung
    Business Intelligence Manager
    Techniker Krankenkasse
    Hamburg Germany
    #IBMChampion
    ------------------------------



  • 7.  RE: Report with 2 date prompts

    Posted Fri February 24, 2023 03:53 AM

    Hi Krista,

    I didnt find a standard way from cognos to uncheck the date selection. BUT.... I think I solved the business case from you just some weeks ago. The customer wanted a prompt page with a prompt: last month / actual month / date selection. By selecting last or actual month cognos didnt show any date selection. The date filter is mandatory and the good thing was that it wasnt shown up or that I have to handle with uncheck the date prompts. Only when I choosed date selection it was shown up by the style variable. The trick is to handle with the prompt when its selected but not needed. Of course, in my case the date prompts are always there but hidden till the moment when the user needs it. Maybe you get some inspiration with my solution transfering the date logic to an data item.

    In the query I created two data items: xDate_from and xDate_to with this logic:

    xDate from:

    xDate to:

    In the filter section of the query I used the 2 data items from above to filter - not the prompt ?date....?

    Filter:

    Regards,
    Hendrik



    ------------------------------
    Hendrik Gebert
    Managing Consultant
    ACP Digital Analytics
    ------------------------------



  • 8.  RE: Report with 2 date prompts

    Posted Fri February 24, 2023 04:30 AM

    I don't know if this is any use to you...I wrote it some time ago so it might need a little tweaking

    http://cognostips.weebly.com/blog/date-prompts



    ------------------------------
    Chris Turner
    ------------------------------



  • 9.  RE: Report with 2 date prompts

    Posted Fri February 24, 2023 04:39 AM
      |   view attached

    There are a few ways I like to do this. First I'll show you my preferred JavaScript-free way of doing it. In this example I'm using two date-range prompts, but this could easily be switched with separate from-to prompts for both. 

    The period selector prompt looks like this:

    In this case the periodselector has logic to handle the filters for the other periods, with special cases for All Data, and the two date ranges.

    The filter in the report query looks like this:

    #case prompt('PeriodSelector','token')
    when 'DateRange' then '[C].[C_Great_outdoors_sales_data_module].[page_7].[Date_] in_range ?DateRange?'
    when 'DateRangeShipped' then '[C].[C_Great_outdoors_sales_data_module].[page_2].[Date_ship_date] in_range ?DateRangeShipped?'
    else prompt('PeriodSelector','token')
    end#

    I also have a similar macro statement inside the one of the data items in the query as well:

    #case prompt('PeriodSelector','token')
    when 'DateRange' then '[C].[C_Great_outdoors_sales_data_module].[page_6].[Order_date]'
    when 'DateRangeShipped' then '[C].[C_Great_outdoors_sales_data_module].[page_6].[Ship_date]'
    else '[C].[C_Great_outdoors_sales_data_module].[page_6].[Order_date]'
    end#

    This lets the end user select how they want to view their data, and if they select a date range prompt it will ignore the other. 

    This works, but it still leaves the problem of the date ranges being visible. I do have a solution (yes in Cogbox) to solve it so it looks like this:

    This uses my performActions script with the following configuration:

    {
        "Control": "PeriodSelector",
        "Start on load": true,
        "Actions": [
            {
                "type": "setDisplay",
                "display": false,
                "name": "DateRange"
            },
            {
                "type": "setDisplay",
                "display": false,
                "name": "DateRangeShipped"
            },
            {
                "type": "setDisplay",
                "display": true,
                "name": {
                    "type": "promptUse",
                    "name": "PeriodSelector"
                }
            }
        ]
    }

    Basically every time the periodselector is changed it will hide both date range prompts, then unhide the selected value. If it doesn't find it, like All Data is 1=1, it simply does nothing. You can replicate this by writing a JS control to do exactly the same thing. Set a validator on the periodPrompt prompt that hides both blocks, then unhide them with getControl(values[0].use). 

    Something along the lines of 

    oControlHost.page.getControl('PeriodPrompt').setValidator((values)=>{

      oControlHost.page.getControl('DateRange').setDisplay(false);

      oControlHost.page.getControl('DateRangeShipped').setDisplay(false);

      oControlHost.page.getControl(values[0].use)?.setDisplay(true);

    })

    The attached report xml has two prompt pages, one without the custom control and one with. If you don't have the premium cogbox, just delete the second prompt page to get it working. 



    ------------------------------
    Paul Mendelson
    ------------------------------

    Attachment(s)