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
  • I tried this too, and received oddly similar results to Poorna's approach.
  • 0
    Certified Associate Developer
    in reply to Richard
    load(
    local!myCDT:{
      {label:"First Row", data:tointeger({1,2,3,4})},
      {label:"Second Row",data:{5,6,7,8}},
      {label:"Third Row",data:{9,0,1,2}}
    },
    {

    a!paragraphField(
      label: "Output", readOnly: true(),
      value: apply(
        fn!sum,
          merge(
            apply(fn!tointeger,local!myCDT[1].data),
            apply(fn!tointeger,local!myCDT[2].data),
            apply(fn!tointeger,local!myCDT[3].data)
          )
        )
      )
    }
    )

    The trick here is using fn!merge to create the myCDT.data[1], myCDT.data[2], myCDT.data[3] arrays before you pass it to fn!sum (note the position of the [1] operator in my example above).  
     
    I had to use fn!tointeger on each of the data elements before the merge command would work because the example arrays at the top are defined as type variant but if you're using a proper CDT this shouldn't be necessary.  To make this work over a dynamic number of data elements you'll have to move the local!myCDT[X].data operator into its own expression that you can use apply on again but aside from that this should work.
     
     
  • OK, so that takes me a bit further,  what I'm actually dealing with deep down is a pseudo chartSeries construct that is appearing in a grid below a chart that has taken some careful programmatic assembly.  So I very much have variable sizes at both dimensions.  Still plugging, although this was a big help.

  • 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
    )
    )
  • 0
    A Score Level 1
    in reply to Jim Schweitzer
    Reduce would be good here but bear in mind there's a known issue with reduce, where variable size arrays cause an error in certain situations.