CDT with an Integer List

I have a result set from a series of operations that looks like:

myCDT:{

label: "some name",

data: 0,1,12,0,14,234

}

"data" is an integer array - but may have a variable number of Elements.

I've got a List of myCDT's and want to create an array of integers that is the sum of each positional integer column (e.g add up all of data[1], data[2], etc)

Any good ideas on how to do this?

Ultimately  all I need is a total row in some grids, but there doesn't seem to be a way to do that.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Associate Developer
    in reply to Richard

    To generalize it you'll need to make a helper function:

    getDataFromCDTList(cdtList, index)

    Defined As: 

      apply(

        fn!index(cdt, _, {}).data

        1+enumerate(fn!length(ri!cdtList.data)

      )

     

    Then to help generate your chart series:

    apply(

      getDataFromCDTList(

      cdtList: local!myCDTList,

      index: _

    ),

    fn!length(local!myCDTList[1].data)

     

    There used to be a SAIL recipe that covered exactly this (what you're effectively doing is transposing tabular data) but I can't seem to find it anymore.

  • Yeah, 'Community' is making it difficult for me to find old references too, the above is throwing errors when I try it though.


    So, can anyone explain why the following is happening:

    I have this data:
    local!cdt:{{label:"Testing",data:{1,2,3,4,5,6}},{label:"Testing2",data: {7,8,9,0,1,3}}}

    I try this function: fn!index(local!cdt.data,2,{})

    I expect: {2;8}

    I get: {7;8;9;0;1;3}
  • see if the following code is of any help.
    load(
    local!cdt: {
    type!LabelValue(
    label: "testing1",
    value: {
    1,
    2,
    3,
    4
    }
    ),
    type!LabelValue(
    label: "testing2",
    value: {
    11,
    22,
    33,
    44
    }
    )
    },
    index(
    merge(
    index(
    local!cdt,
    1,
    "value",
    {}
    ),
    index(
    local!cdt,
    2,
    "value",
    {}
    )
    ),
    2
    )
    )