Elimination rule

a!localVariables(
local!data: {
     a!map(id: 1, classid: 1702116260, value: - 115),
     a!map(id: 2, classid: 1702116260, value: 190),
     a!map(id: 3, classid: 1702116260, value: - 190),
     a!map(id: 4, classid: 1702116260, value: 115),
     a!map(id: 5, classid: 1702116260, value: 210),
     a!map(id: 6, classid: 1702116260, value:104)
},

local!choiceLabels: {
          concat(1702116260, 104), 
          concat(1702116260, 210)
},

local!choicevalues: { 5, 6 },


local!choiceLabels
)

I want to eliminate all the rows in local!data that has a corresponding negative value and add their classid + value in choice labels and ids in choicevalues

e.g. value -115 with id 1 has value 115 with id 4... so both need excluded.

whereas values 104 and 210 has no corresponding negative fields to include those in choiceLabels/ choiceValues

  Discussion posts and replies are publicly visible

  • a!localVariables(
      local!data: {
        a!map(id: 1, classid: 1702116260, value: - 115),
        a!map(id: 2, classid: 1702116260, value: 190),
        a!map(id: 3, classid: 1702116260, value: - 190),
        a!map(id: 4, classid: 1702116260, value: 115),
        a!map(id: 5, classid: 1702116260, value: 210),
        a!map(id: 6, classid: 1702116260, value: 104)
      },
      reject(
        fn!isnull,
        a!forEach(
          local!data,
          a!localVariables(
            local!inverse: - fv!item.value,
            local!hasInverseInList: contains(
              tointeger(local!data.value),
              tointeger(local!inverse)
            ),
            if(local!hasInverseInList, null, fv!item)
          )
        )
      )
    )

  • Thanks Matt that worked, I need a slight variation where i need to do grouping by couple of fields and then sum those values- 

    a!localVariables(
    local!data: {
      a!map(id: 1, date: "12/2/2023", code: 1234, value: -120),
    a!map(id: 2, date: "12/2/2023", code: 1234, value: 190),
    a!map(id: 3, date: "12/2/2023", code: 1234, value: -190),
    a!map(id: 4, date: "12/2/2023", code: 1234, value: 115),
    a!map(id: 5, date: "12/4/2023", code: 1234, value: 210),
    a!map(id: 7, date: "12/4/2023", code: 1234, value: -115),
    a!map(id: 6, date: "12/4/2023", code: 3456, value: 104),
    a!map(id: 8, date: "12/4/2023", code: 3456, value: 210),
    a!map(id: 9, date: "12/5/2023", code: 1234, value: 104),
    a!map(id: 10, date: "12/5/2023", code: 5678, value:115),
    a!map(id: 11, date: "12/5/2023", code: 5678, value: 210),
    a!map(id: 12, date: "12/5/2023", code: 1234, value:-104)
    },

    local!choiceLabels: {

    /* I need logic to do GROUPING of local!data by date and code then SUM up those values add to the list where sum is > 0 */


       concat(12/2/2023, " ", 1234," " ,-120+190-190+115),
       concat(12/2/2023, " ", 1234," ", 210-115),
       concat(12/4/2023, " ", 3456," ", 104+210),
       concat(12/5/2023, " ", 1234," ", 104-104)   <-- SKIP THIS AS SUM (value)=0

       concat(12/5/2023, " ", 5678," ", 115+210)
    },


    local!choiceLabels
    )

  • 0
    Certified Lead Developer
    in reply to ravib0008

    a!localVariables(
      local!data: {
        a!map(id: 1, date: "12/2/2023", code: 1234, value: -120),
        a!map(id: 2, date: "12/2/2023", code: 1234, value: 190),
        a!map(id: 3, date: "12/2/2023", code: 1234, value: -190),
        a!map(id: 4, date: "12/2/2023", code: 1234, value: 115),
        a!map(id: 5, date: "12/4/2023", code: 1234, value: 210),
        a!map(id: 7, date: "12/4/2023", code: 1234, value: -115),
        a!map(id: 6, date: "12/4/2023", code: 3456, value: 104),
        a!map(id: 8, date: "12/4/2023", code: 3456, value: 210),
        a!map(id: 9, date: "12/5/2023", code: 1234, value: 104),
        a!map(id: 10, date: "12/5/2023", code: 5678, value:115),
        a!map(id: 11, date: "12/5/2023", code: 5678, value: 210),
        a!map(id: 12, date: "12/5/2023", code: 1234, value:-104)
      },
      local!map: a!forEach(
        local!data,
        a!map(date: fv!item.date, code: fv!item.code)
      ),
      reject(
        fn!isnull,
        a!forEach(
          a!forEach(
            union(local!map, local!map),
            a!map(
              date: fv!item.date,
              code: fv!item.code,
              value: a!localVariables(
                local!date: fv!item.date,
                local!code: fv!item.code,
                sum(
                  reject(
                    fn!isNull,
                    a!forEach(
                      local!data,
                      if(
                        and(
                          fv!item.date = local!date,
                          fv!item.code = local!code
                        ),
                        fv!item.value,
                        ""
                      )
                    )
                  )
                )
              )
            )
          ),
          if(fv!item.value = 0, "", fv!item)
        )
      )
    )

     Hello  , try to concat the list which comes in result.