🕐 5 min read
This example ranks profit values within each region-year combination.
"query": {
"fields": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
},
{
"fieldCaption": "Sales",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM",
"tableCalculation": {
"tableCalcType": "RANK",
"dimensions": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
}
],
"rankType": "COMPETITION"
}
}
]
}
In the response, each region-year combination will have profit values ranked from highest to lowest.
This example shows what percentage each profit value represents of the total profit for that region-year.
"query": {
"fields": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
},
{
"fieldCaption": "Sales",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM",
"tableCalculation": {
"tableCalcType": "PERCENT_OF_TOTAL",
"dimensions": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
}
]
}
}
]
}
In the response, each profit value will be shown as a percentage of the total profit for that specific region and year.
This example shows cumulative profit over time for each region.
"query": {
"fields": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
},
{
"fieldCaption": "Sales",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM",
"tableCalculation": {
"tableCalcType": "RUNNING_TOTAL",
"dimensions": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
}
],
"restartEvery": {
"fieldCaption": "Order Date",
"function": "YEAR"
}
}
}
]
}
This example shows how much profit changed compared to the previous year.
"query": {
"fields": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
},
{
"fieldCaption": "Sales",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM",
"tableCalculation": {
"tableCalcType": "DIFFERENCE_FROM",
"dimensions": [
{
"fieldCaption": "Order Date",
"function": "YEAR"
}
],
"relativeTo": "PREVIOUS"
}
}
]
}
The response shows the absolute difference in profit compared to the previous year for each region.
This example shows a three-year moving average of profit for each region.
"query": {
"fields": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
},
{
"fieldCaption": "Sales",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM",
"tableCalculation": {
"tableCalcType": "MOVING_CALCULATION",
"dimensions": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
}
],
"aggregation": "SUM",
"previous": -2,
"next": 1,
"includeCurrent": true
}
}
]
}
There is an option to add secondary table calculations.
This example shows how to first calculate running totals, then show the percentage change in running totals.
"query": {
"fields": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
},
{
"fieldCaption": "Sales",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM"
},
{
"fieldCaption": "Profit",
"function": "SUM",
"tableCalculation": {
"tableCalcType": "RUNNING_TOTAL",
"dimensions": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
}
],
"aggregation": "SUM",
"secondaryTableCalculation": {
"tableCalcType": "PERCENT_DIFFERENCE_FROM",
"dimensions": [
{
"fieldCaption": "Region"
},
{
"fieldCaption": "Order Date",
"function": "YEAR"
}
],
"relativeTo": "PREVIOUS"
}
}
}
]
}