Skip to main content
October 31, 2023
Solved

sum a values in a column

  • October 31, 2023
  • 3 replies
  • 0 views

I want to get the sum of values from a column in the expression editor and I want to use that expression object in an interface to show my Sum which I calculated.

    Best answer by stefanhelzle0001

    I am not really sure what you are looking for. But to calculate the sum of all values of a field in a list of records have a look at this code snippet:

    a!localVariables(
      local!test1: {
        {
          item: "stapler",
          name: "Mike",
          countryId: 1
        },
        {
          item: "printer",
          name: "Larrys",
          countryId: 2
        },
        {
          item: "printer",
          name: "Larry",
          countryId: 2
        },
        {
          item: "laptop",
          name: "Mike",
          countryId: 1
        },
        {
          item: "glass",
          name: "Mike",
          countryId: 3
        }
      },
    
    
      sum(local!test1.countryId)
    )

    3 replies

    stefanhelzle0001
    Brainy
    October 31, 2023

    I am not really sure what you are looking for. But to calculate the sum of all values of a field in a list of records have a look at this code snippet:

    a!localVariables(
      local!test1: {
        {
          item: "stapler",
          name: "Mike",
          countryId: 1
        },
        {
          item: "printer",
          name: "Larrys",
          countryId: 2
        },
        {
          item: "printer",
          name: "Larry",
          countryId: 2
        },
        {
          item: "laptop",
          name: "Mike",
          countryId: 1
        },
        {
          item: "glass",
          name: "Mike",
          countryId: 3
        }
      },
    
    
      sum(local!test1.countryId)
    )

    November 3, 2023

    You can query the data for the column from the database and then you use the sum() for addition.

    In the above, for a Order Line Item record, the data is queried for a column and then addition has been done

    November 9, 2023

    Thank you

    This is working