Cognos Analytics

 View Only
Expand all | Collapse all

Is there a way using Cognos to do "advanced" string concatenation?

  • 1.  Is there a way using Cognos to do "advanced" string concatenation?

    Posted Fri April 16, 2021 06:35 PM
    Edited by System Fri January 20, 2023 04:19 PM
    Hi all,
         I know there is a concat function to join 2 strings, but is there a way to concatenate a larger number of pieces involving complex strings made from complex math functions:

    e.g.

    Concat (string(complex math stuff 1)) separated by a left parenthesis followed by string(complex math stuff 2) followed by an 'M' and right parenthesis, e.g.

    105 (48 M)

    Other languages do things like str(complex math stuff 1) && " (" && str(complex math stuff 2) && " M)"

    Currently when I try using str I get an error "The vendor specific function "str" is not supported."

    Thanks in advance.  This forum has been very helpful for me as I learn Cognos.

    Jim

    ------------------------------
    Jim Denton
    ------------------------------
    #CognosAnalyticswithWatson


  • 2.  RE: Is there a way using Cognos to do "advanced" string concatenation?

    Posted Sun April 18, 2021 12:18 AM

    Hi Jim,
    You can use + to concatenate two strings, you can use cast ( <expression>, varchar(100)) to turn most anything into a string.
    E.g.
    cast ( cast ( 3/4 + 5/6 , decimal(10,2)) , varchar(20)) + ' some text ' + cast ( 4 + 3 + 4/5 , varchar (10))

    The answer is: 1.58 some text 7.8

    // Henk



    ------------------------------
    HENK CAZEMIER
    ------------------------------



  • 3.  RE: Is there a way using Cognos to do "advanced" string concatenation?

    Posted Sun April 18, 2021 07:35 PM

    Further to Henk's reply, subject to your requirement, review if your goal is better suited by applying format specifications on items projected to a report.

    Type conversion (CAST), will convert non-character types to character types with a specific format. Meanwhile formatting is fairly extensive and locale aware.

    See also concatenation (operators) and cast in the docs

    https://www.ibm.com/docs/en/cognos-analytics/11.0.0?topic=modeling-using-expression-editor



    ------------------------------
    NIGEL CAMPBELL
    ------------------------------