Cognos Analytics

Cognos Analytics

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

 View Only
  • 1.  CAST numeric syntax

    Posted Mon June 03, 2019 07:56 AM
    Hello.  I am a new Cognos user and I am having trouble finding syntax requirements when using CAST to convert a value to a number.  In the code below, the value is lborres and it is stored as text (because it is a tall/skinny relational table that has text and numeric values).  The value I want is also a number with one decimal place.  I have tried using integer, which obviously doesn't work, and I've tried decimal, real, and numeric.  I don't think I know the correct parameters to include.  Here is my sample code: 

    cast (case when [C].[FAST].[lbx_34276].[test]='Hemoglobin A1c' then [C].[FAST].[lbx_34276].[lborres] else null end, decimal(??))

    The ?? is where I am stumped, I think.  The typical values are in the format X.Y or sometimes 1X.Y (e.g., 7.4 or 10.2).  

    Any help pointing me where to find syntax when using CAST, particularly for numeric values and/or a solution to the problem above would be appreciated.

    Thank you.

    ------------------------------
    David Provenghi
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: CAST numeric syntax

    Posted Mon June 03, 2019 09:20 AM
    Edited by System Admin Fri January 20, 2023 04:23 PM
      |   view attached

    @David Provenghi The syntax for cast to decimal is : cast([Data Item],decimal(precision,scale)) for example:  ​ cast([Value],decimal(5,2))

    A tip to for getting the syntax for a function in Authoring -- In the expression editor,  click on a function you would like to get more details on and it will be displayed in the info window.



    ------------------------------
    DENNY NAREZNY
    ------------------------------