Hi gooddata team, is there any way to get the gran...
# gooddata-ui
c
Hi gooddata team, is there any way to get the grandTotal fields in the api, like they show up in the cloud dashboards? looking for these, and the rollup (natural) fields "grandTotals": [ { "data": [ [ 25582.810002999995,
"grandTotals": [], they always show up blank in the response
m
Hi, may I know how are you retrieving this? Are you using the AFM endpoint described here: https://www.gooddata.com/docs/cloud/api-and-sdk/api/access_raw_data_through_api/?
c
yes that's correct
m
You will need to include the total array with the corresponding metric and dimension when calling the
api/v1/actions/workspaces/<workspace_id>/execution/afm/execute
endpoint. For example:
Copy code
"totals": [
            {
                "localIdentifier": "total_sum_m_order_unit_quantity_sum_by_a_customer_state_0",
                "function": "SUM",
                "metric": "m_order_unit_quantity_sum",
                "totalDimensions": [
                    {
                        "dimensionIdentifier": "dim_1",
                        "totalDimensionItems": [
                            "measureGroup"
                        ]
                    }
                ]
            }
        ]
This is the complete body of my test:
Copy code
{
  "resultSpec": {
    "dimensions": [
      {
        "localIdentifier": "dim_0",
        "itemIdentifiers": [
          "a_customer_state",
          "a_customer_id",
          "a_customer_email"
        ],
        "sorting": [
          {
            "attribute": {
              "attributeIdentifier": "a_customer_state",
              "sortType": "DEFAULT"
            }
          }
        ]
      },
      {
        "localIdentifier": "dim_1",
        "itemIdentifiers": [
          "measureGroup"
        ]
      }
    ],
    "totals": [
      {
        "localIdentifier": "total_sum_m_order_unit_quantity_sum_by_a_customer_state_0",
        "function": "SUM",
        "metric": "m_order_unit_quantity_sum",
        "totalDimensions": [
          {
            "dimensionIdentifier": "dim_1",
            "totalDimensionItems": [
              "measureGroup"
            ]
          }
        ]
      }
    ]
  },
  "execution": {
    "measures": [
      {
        "localIdentifier": "m_order_unit_cost_sum",
        "definition": {
          "measure": {
            "item": {
              "identifier": {
                "id": "order_unit_cost",
                "type": "fact"
              }
            },
            "aggregation": "SUM"
          }
        }
      },
      {
        "localIdentifier": "m_order_unit_quantity_sum",
        "definition": {
          "measure": {
            "item": {
              "identifier": {
                "id": "order_unit_quantity",
                "type": "fact"
              }
            },
            "aggregation": "SUM"
          }
        }
      }
    ],
    "attributes": [
      {
        "label": {
          "identifier": {
            "id": "customer_state",
            "type": "label"
          }
        },
        "localIdentifier": "a_customer_state"
      },
      {
        "label": {
          "identifier": {
            "id": "customer_id",
            "type": "label"
          }
        },
        "localIdentifier": "a_customer_id"
      },
      {
        "label": {
          "identifier": {
            "id": "customer_email",
            "type": "label"
          }
        },
        "localIdentifier": "a_customer_email"
      }
    ],
    "filters": [
      {
        "relativeDateFilter": {
          "dataset": {
            "identifier": {
              "id": "customer_created_date",
              "type": "dataset"
            }
          },
          "granularity": "YEAR",
          "from": 0,
          "to": 0
        }
      }
    ],
    "auxMeasures": []
  },
  "settings": {}
}
Note that if you wish to get the rollup, then your totals array should look like this instead:
Copy code
"totals": [
    {
        "localIdentifier": "total_sum_m_order_unit_quantity_sum_by_a_customer_state_0",
        "function": "SUM",
        "metric": "m_order_unit_quantity_sum",
        "totalDimensions": [
            {
                "dimensionIdentifier": "dim_1",
                "totalDimensionItems": [
                    "measureGroup"
                ]
            }
        ]
    },
    {
        "localIdentifier": "total_nat_m_order_unit_cost_sum_by_a_customer_state_0",
        "function": "NAT",
        "metric": "m_order_unit_cost_sum",
        "totalDimensions": [
            {
                "dimensionIdentifier": "dim_1",
                "totalDimensionItems": [
                    "measureGroup"
                ]
            }
        ]
    }
]
You must use the NAT function alongside the regular SUM
c
Thank you so much! I will give this a shot