Cognos Analytics

 View Only
  • 1.  calendar relativ date and _as_of_date

    Posted Thu September 05, 2024 07:26 AM

    Hi,

    if i am not wrong the standard calendar (relativ dates) are based on the global variable _as_of_date.

    Is it possible to create a new calendar (relative dates) based on a 
    calculated date (eg. of a report) or a calculated date within a data module?

    Maybe someone can give some hints or provide an example?

    Thanks in advance.

    BR
    Andreas



    ------------------------------
    Andreas Wycisk
    ------------------------------


  • 2.  RE: calendar relativ date and _as_of_date

    Posted Thu September 05, 2024 10:04 AM
    Edited by Andrei Istomine Thu September 05, 2024 10:06 AM

    Hi Andreas,

    You can check if Setting a dynamic _as_of_date parameter  will work for you.

    Useful hints are in C12 Calendar samples and the IBM video  Big Blue Helps - Global parameters (11.0.7+)

    If that will not help then it is possible to modify Calendar Relative Dates filters to use prompt() instead of $_as_of_date

    E.g. in YTD filter replace reference to $_as_of_date with  prompt ('CurrentDate','date', $_as_of_date ) 

    Obviously, this is not supported or encouraged by IBM Cognos Support :-)

    // This is a template expression that is used by the column property 'Lookup reference'.
    // To pass validation, the line below must remain as a comment. Do not remove the forward slashes.
    // validate: 1 = 1
    #$_this.parent.idForExpression# >=
            #queryValue($_this.parent.split.ref + '.dYear',
                        $_this.parent.split.ref + '.TheDate = ' + $_as_of_date)#
    AND   #$_this.parent.idForExpression# <= #$_as_of_date#
    
    /*********  REPLACE  ************/
    
    // This is a template expression that is used by the column property 'Lookup reference'.
    // To pass validation, the line below must remain as a comment. Do not remove the forward slashes.
    // validate: 1 = 1
    #$_this.parent.idForExpression# >=
          #queryValue($_this.parent.split.ref + '.dYear',
                      $_this.parent.split.ref + '.TheDate = ' + prompt ('CurrentDate','date', $_as_of_date ) )#
      AND   #$_this.parent.idForExpression# <= #prompt ('CurrentDate','date', $_as_of_date )#



    ------------------------------
    Andrei Istomine
    Open to work - anything Cognos
    https://www.linkedin.com/in/andreii/
    ------------------------------



  • 3.  RE: calendar relativ date and _as_of_date

    Posted Fri September 06, 2024 02:50 AM

    Hi Andrei,

    thanks for your answer.

    I am looking for an dynamic approach (not default values).

    The _as_of_date is the current date but i need always the "last of month - previous month" as reference date 

    or eg.  "last invoice date" which is the result of an query and can change multiple times per month.

    Any ideas?



    ------------------------------
    Andreas Wycisk
    ------------------------------



  • 4.  RE: calendar relativ date and _as_of_date

    Posted Fri September 06, 2024 08:03 AM

    Hi Andreas,

    Instead of the default value $_as_of_date  you can try  a queryValue function call to retrieve that Reference date  in the Calendar filter macro #prompt ('CurrentDate','date', $_as_of_date )

    There is no many examples for queryValue usage on the net. This one from @Paul Mendelson could be useful https://cognospaul.com/2019/06/06/quickie-use-new-macro-function-queryvalue/

    If you can build a simplified use case with the Cognos samples we can get together to troubleshoot.

    Cheers! 



    ------------------------------
    Andrei Istomine
    Open to work - anything Cognos
    https://www.linkedin.com/in/andreii/
    ------------------------------



  • 5.  RE: calendar relativ date and _as_of_date

    Posted Sun September 08, 2024 06:38 AM
    Hi Andreas,
     
    With the queryValue function, you can access all elements in your data module.
     
    This allows the filters in the calendar to be adjusted accordingly.
     
    The line where the reference date is determined (usually with _as_of_date) is then related to an element from a table:
    let refDate = queryValue('[ORDER_HEADER].[LastOrderDate]');
     
    In my example (using the Cognos Adventure and Leisure data), "LastOrderDate" is the last date in the Order_Header table:
    maximum(ORDER_DATE for report)
     
    Here is the result: Current year, previous year, current month, and previous month now refer to the last order date.
     
    Tip for Cognos User Group Germany, Swiss, Austria members: I created the example on our CUG Cognos server.

    Changes in Calender Filter definition:
    Tip for Cognos User Group Germany, Swiss, Austria members: I created the example on our CUG Cognos server.
     


    ------------------------------
    Jens Bäumler
    Cognos Analytics, Planning Analytics and watsonx
    Apparo Group
    Germay
    www.apparo.de
    ------------------------------



  • 6.  RE: calendar relativ date and _as_of_date

    Posted Mon September 09, 2024 05:18 AM

    This example is when you want to give user ability to select what will be used as a reference date. In the report place a prompt with these values. The name of the parameter is "paramRelTimeDate".

    Prompt to select reference date.
    "paramRelTimeDate" is used inside of the relative time macro. Normally, it will take default value which will make that parameter futile. If the above prompt does exist in a report, and if a user selects something from that prompt, then user selection will override the global parameter value.
    # 
    let calTable = $_this.parent.split.ref;
    let today = substr($current_timestamp, 0, 10);
    
    Let varLastWorkingDay = queryValue(calTable + '.Previous_workday', calTable + ' .TheDate = ' + today);
    Let varUseYesterday = _add_days (today, -1);
    Let varUseLastSunday = _add_days (today, '-' +
                                     queryValue(calTable + '.DayOfWeek', calTable + ' .TheDate = ' + today));
    Let varAsOfDate = $_as_of_date;                                  
    
    let refDateGlobal = 
        case tolower($[Time Perspective] )
        when 'last working day'   then varLastWorkingDay
        when 'use yesterday'   then varUseYesterday
        when 'use last sunday' then varUseLastSunday
        else varAsOfDate
        end;
        
    Let refDate = 
        case paramValue( 'paramRelTimeDate', '1900-01-01' ) 
        when "'1900-01-01'" then refDateGlobal
        when "'GUI menu'" then refDateGlobal
        when "'last working day'" then varLastWorkingDay
        when "'use yesterday'" then varUseYesterday
        when "'use last Sunday'" then varUseLastSunday
        when "'use _as_of_date'" then varAsOfDate
        else substr( ParamValue ( 'paramRelTimeDate', '', 'token' ), 1, 10 )
        end;
    
    let parentId = $_this.parent.idForExpression;              
    parentId + ' = ' +  refDate;
    #
    
    Table with relative dates.


    ------------------------------
    Milan Milovanovic
    ------------------------------