Skip to main content
New Participant
April 23, 2025
Question

Sum of data show in list of dictionary

  • April 23, 2025
  • 5 replies
  • 5 views

Hiii,

I want to add the Total Cost . It show the data in below format. I am using sum function to add the data but it is not working.

List of Dictionary - 7 items

    • Dictionary
        • Total_Cost19000(Number (Integer))
          • Dictionary
              • Total_Cost18000(Number (Integer))
                • Dictionary
                    • Total_Cost15000(Number (Integer))
                      • Dictionary
                          • Total_Cost7000(Number (Integer))
                            • Dictionary
                                • Total_Cost9000(Number (Integer))
                                  • Dictionary
                                      • Total_Cost13000(Number (Integer))
                                        • Dictionary
                                            • Total_Cost1500(Number (Integer))

                                            5 replies

                                            stefanhelzle0001
                                            Brainy
                                            April 23, 2025
                                            but it is not working.

                                            What exactly does this mean? And, can you share your code?

                                            New Participant
                                            April 24, 2025

                                            This is the Code

                                            a!localVariables(
                                            local!CostData: a!queryEntity(
                                            entity: cons!ERV_dataEntity,
                                            query: a!query(
                                            selection: a!querySelection(
                                            columns: a!queryColumn(field: "totalCost", alias: "Total_Cost")
                                            ),
                                            logicalExpression: a!queryLogicalExpression(
                                            operator: "AND",
                                            filters: {
                                            a!queryFilter(field: "totalCost", operator: "not null"),
                                            a!queryFilter(
                                            field: "rmApproval",
                                            operator: "=",
                                            value: true
                                            )
                                            }
                                            ),
                                            pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 20)
                                            )
                                            ).data,
                                            local!CostData
                                            )

                                             And see below this is the output and I want to add all the total Cost Value.

                                            List of Dictionary - 7 items

                                              • Dictionary
                                                  • Total_Cost19000(Number (Integer))
                                                    • Dictionary
                                                        • Total_Cost18000(Number (Integer))
                                                          • Dictionary
                                                              • Total_Cost15000(Number (Integer))
                                                                • Dictionary
                                                                    • Total_Cost7000(Number (Integer))
                                                                      • Dictionary
                                                                          • Total_Cost9000(Number (Integer))
                                                                            • Dictionary
                                                                                • Total_Cost13000(Number (Integer))
                                                                                  • Dictionary
                                                                                      • Total_Cost1500(Number (Integer))

                                                                                    stefanhelzle0001
                                                                                    Brainy
                                                                                    April 24, 2025

                                                                                    This makes your code more readable.

                                                                                    Did you consider to do that aggregation directly in the query?

                                                                                    If this does not work for you, [mention:f5e81b8502fa4e77ad12697686a4fc56:e9ed411860ed4f2ba0265705b8793d05] has the solution.

                                                                                    mathieud0001
                                                                                    Brainy
                                                                                    April 23, 2025

                                                                                    a!localVariables(
                                                                                      local!dictionary: {
                                                                                        {
                                                                                          totalCost: 1000
                                                                                        },
                                                                                        {
                                                                                          totalCost: 2000
                                                                                        },
                                                                                        {
                                                                                          totalCost: 3000
                                                                                        }
                                                                                      },
                                                                                      sum(local!dictionary.totalCost)
                                                                                    )