Azure cost management API Get Forecast not returning resource group name

Rajesh Nerenki 1 Reputation point
2020-08-07T11:44:39.647+00:00

I'm using Azure management REST API to get the forecast value for each resource group at the subscription scope. Though I've specified the grouping dimension as ResourceGroup, the response contains the overall forecast for the subscription and not for each resource group. It appears the grouping is not working.

POST request url
https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.CostManagement/forecast?api-version=2019-11-01

Request Body

{
  "type": "ActualCost",
  "timeframe": "MonthToDate",
  "dataSet": {
    "granularity": "None",
    "aggregation": {
      "totalCost": {
        "name": "PreTaxCost",
        "function": "Sum"
      }
    },
    "sorting": [
      {
        "direction": "ascending",
        "name": "UsageDate"
      }
    ],
    "grouping": [
      {
        "type": "Dimension",
        "name": "ResourceGroupName"
      }
    ],
    "filter": {
      "Dimensions": {
        "Name": "PublisherType",
        "Operator": "In",
        "Values": [ "azure" ]
      }
    }
  },
  "includeActualCost": false,
  "includeFreshPartialCost": false
}

Currently in order to get the resource group forecast, I'm making a individual call at the resource group scope which is time consuming since there are hundreds of resource groups

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,035 questions
{count} votes

2 answers

Sort by: Most helpful
  1. SadiqhAhmed-MSFT 37,686 Reputation points Microsoft Employee
    2020-08-10T09:40:41.24+00:00

    anonymous user Sorry for the delay. Appreciate your patience in this matter.

    Forecast API does not support “Group by” or “Grouping” properties to provide a Forecast for each resource group when the dimension is grouped.

    It will provide the total forecast of the subscription, and for the resource group when you call Forecast API at RG scope. In order to get Forecast for multiple resource groups at once, I suggest you use filter property:

        "filter": {
               "Dimensions": {
               "Name": "PublisherType",
               "Operator": "In",
               "Values": [ "azure" ]
    

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.


  2. AssafL 1 Reputation point
    2020-10-21T12:24:59.213+00:00

    Hi
    When I call the forecast API at subscription level (https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.CostManagement/forecast?api-version=2019-10-01) with this simple request body

    {
      "type": "Usage",
      "timeframe": "MonthToDate",
      "dataset": {
        "granularity": "Daily"
      },
      "includeActualCost": false,
      "includeFreshPartialCost": false
    }
    

    the call gets the error:

    Invalid query definition: Invalid dataset grouping: 'BillingPeriod'; valid values: 'ResourceGroup','ResourceGroupName'....

    When I simply change the url to API of type query https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.CostManagement/query?api-version=2019-10-01 I get a response
    Any ideas?