Cognos Analytics

Cognos Analytics

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

 View Only
Expand all | Collapse all

Select Year-Month in prompt Page

  • 1.  Select Year-Month in prompt Page

    Posted Fri April 29, 2022 07:30 AM
    Hi Guys,

    I need help in selecting the current year and month as default(Eg: 2022-02) on the prompt page using JS.

    I' am displaying Year-Month in values prompt like:
    2022-04
    2022-03
    2022-02 etc 
    It has some junk data like 2105-05 in the values list so, I' am unable to use this script to select current month
    var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
    if (fW)
    {
    fW._oLstChoicesCurrentPeriodYear.options[3].selected = true;
    listBoxCurrentPeriodYear.checkData();

    Data Item "Year-Month" is not in the Date data type,
    It is in varchar :- convert(varchar(7), [Date], 126) 
    so it's difficult to set the current month as default.
    Needed JS script to select the current year and month, Help me to find the solution.

    Thanks!

    ------------------------------
    P S
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 08:15 AM
    Hi,

    before I get deeper into another solution: is your "current month" somewhere stored in your data source or can you use current_date()? If yes, you can use data instead of JS to achieve what you're looking for.

    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 3.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 08:30 AM
    Hi Robert,

    Thanks for the reply.
    Yes, The Year-Month data type is stored in the data source,
    Using the data column I' am converting it into varchar as year-month{convert(varchar(7), [Date], 126)}

    ------------------------------
    P S
    ------------------------------



  • 4.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 08:43 AM

    Hi,

     

    my approach for dynamic default values is to overwrite the default value in the prompt and data query.

    Example:

    I create a prompt for "Month key" and added a second data item which contains the key for the current month. If it's not stored in the calendar table, you can use manual SQL in {} or create a simple join. I've changed the content of Month key to an If-Then-Else statement that will return -1 if the months key equals the current month.

    On the page I set the default value for the prompt to -1:

    Now I just must do a modified filtering on the data query where I also added the current months data item. The filter has to look like:

    Finished. Each current month will have the key -1 applied to and as the prompt has this as default value your current month will always be pre-selected.

    My sample data runs only until 2013... but it works:
    Hope this might be a solution for your issue. The challenge is to get the current month accordingly out of your data.




    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 5.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 08:56 AM
    Thanks for the solution.
    Is there any other solution, why because I need to change all Detail filters in the queries 
    there are around 15queries

    ------------------------------
    P S
    ------------------------------



  • 6.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 08:59 AM
    That's how I do it as I'm not capable to write JS. Of course there could also be a solution with JS, but I cannot supply it.
    Someone else have to chime in here... :)

    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 7.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 09:15 AM
    I use a very similar approach, and I've never tried to do it using JS. Is there a way the data can be scrubbed before it gets into the report to make your job easier?

    ------------------------------
    Jonathan McKnight
    5x IBM Champion
    Business Intelligence Analyst
    Nashville, TN
    www.linkedin.com/in/jonathanmcknight
    ------------------------------



  • 8.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 09:33 AM
    Hi Jonathan,

    The only improvement that comes to mind is to move the filter from the report to the FM model/data module so that it can be reused in each report, rather than creating this approach in the reports themselves.

    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 9.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 09:47 AM
    Hi Robert,

    How you are showing only month and year in the prompt screen like these 


    I' am unable to do it before so I converted it into varchar to get as year-month

    ------------------------------
    P S
    ------------------------------



  • 10.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 09:51 AM
    Hi,
    that's because my calendar core table holds all necessary columns like day, quarter, month, week, year, etc. as numeric and char keys + labels and other stuff. So I don't have to convert anything in my DWH. We don't know your data source. So it's up to you and/or your data modeler to check on this.

    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 11.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 10:02 AM
    Okay,
    Can you suggest how to convert YYYY-MM-DD to YYYY-MM in date format at the report level?
    I mean year and month in "Date" data type.

    ------------------------------
    P S
    ------------------------------



  • 12.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 10:58 AM

    Hi,

    what I show up in my sample is a VARCHAR2 label column ready calculated on db level. If you want to change your date field to another label type, you have to use the right function - depending on your data base provider. Then look up the formating options and adjust them accordingly.

    Here are the formats for Oracle:

    MM Numeric month (e.g., 07)
    MON Abbreviated month name (e.g., JUL)
    MONTH Full month name (e.g., JULY)
    DD Day of month (e.g., 24)
    DY Abbreviated name of day (e.g., FRI)
    YYYY 4-digit year (e.g., 1998)
    YY Last 2 digits of the year (e.g., 98)
    RR Like YY, but the two digits are ``rounded'' to a year in the range 1950 to 2049. Thus, 06 is considered 2006 instead of 1906
    AM (or PM) Meridian indicator
    HH Hour of day (1-12)
    HH24 Hour of day (0-23)
    MI Minute (0-59)
    SS Second (0-59)


    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 13.  RE: Select Year-Month in prompt Page

    Posted Fri April 29, 2022 04:54 PM
    Hi,

    You might use a Custom Control to achieve this:

    https://community.ibm.com/community/user/businessanalytics/blogs/steven-macko/2018/09/10/javascript-samples-for-ibm-cognos-analytics


    ------------------------------
    JEAM COELHO
    Cognos Solution Architect

    LinkedIn: https://www.linkedin.com/in/jeamcoelho/
    ------------------------------



  • 14.  RE: Select Year-Month in prompt Page

    Posted Mon May 02, 2022 03:49 AM

    My personal favourite solution for this type of (common) problem, is to have Index values in your Period data source in the data warehouse.

    For example, you can add 4 columns to your Period table, with:
    DAY_INDEX
    WEEK_INDEX
    MONTH_INDEX
    YEAR_INDEX

    These fields contain 0 for current day/week/month/year, -1 for previous, 1 for next, etc.

    This allows you to create simple dropdown prompt boxes, that you can order, and display then the common label for the Period, but use the index as parameter value.

    The great thing of such solution, is that this makes it very easy to schedule reports on previous/current week or month or day, a very common way to schedule reports in businesses. 
    The downside is that currently this solution isn't made possible on pure date selection prompts (via date promptbox) and when you look at the assigned prompts in a scheduled report, Cognos always displays the label, which of course gets updated every week. So if you schedule in January a monthly report and set the report to use -1 as parameter for the month, then the scheduled report will show as prompt parameter in the UI a label with December. 2 months later, the report will run for February, but a user looking at the schedule parameters, will still see "December" (although this is just the incorrect label for the correct setting of -1).

    Hope that's clear.
    I used to be good at creating Javascript solutions for this kind of problems, but since the Javascripts are now stored not in the report but on the server, it's a bit more work trying to prep such a change. I personally now try to avoid it, as this creates risks thus more time in test/development for future releases. 

    Kind regards,
    Joeri



    ------------------------------
    Joeri Willems
    ------------------------------



  • 15.  RE: Select Year-Month in prompt Page

    Posted Tue May 03, 2022 07:54 AM
    Your solution seems like a good idea. I may have to give it a try at some point. Are the index columns are calculated or are you rebuilding your date table every night?

    ------------------------------
    Jonathan McKnight
    5x IBM Champion
    Business Intelligence Analyst
    Nashville, TN
    www.linkedin.com/in/jonathanmcknight
    ------------------------------



  • 16.  RE: Select Year-Month in prompt Page

    Posted Tue May 03, 2022 08:22 AM
    these tables are updated on each etl run.

    Sent from my iPhone




  • 17.  RE: Select Year-Month in prompt Page

    Posted Tue May 03, 2022 08:35 AM
    Hi Joeri,

    in our solution, a time dimension is formed daily using DENSE_RANK() OVER(ORDER BY [year]) etc. It works fine in sql server also for weeks and days.

    Kind regards,
    Michael

    ------------------------------
    Michael Kirschsiefen
    ------------------------------



  • 18.  RE: Select Year-Month in prompt Page

    Posted Tue May 03, 2022 08:42 AM
    Hi Michael,

    I guess using a dense_rank to calculate indexes on the fly would work too, although it doesnt automatically identify the current period if there exist also future dates in your data. 

    Sent from my iPhone