question

RajeshNerenki-2574 avatar image
0 Votes"
RajeshNerenki-2574 asked VinayakNaik-8841 edited

Azure cost management API Get Forecast not returning resource group name

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
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for reaching out to us. We are investigation this issue and will get back to you shortly.

0 Votes 0 ·

anonymous user Checking in to see if the above answer helped. If yes, please do "Accept Answer" and up-vote it. Let us know if there are still any additional issues we can help with.

0 Votes 0 ·

anonymous user We haven't heard back from you. If you have any questions, please reply and we will gladly continue the discussion.

0 Votes 0 ·
SadiqhAhmed-MSFT avatar image
0 Votes"
SadiqhAhmed-MSFT answered SadiqhAhmed-MSFT commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @SadiqhAhmed-MSFT for your reply. Using filter condition is not an option as there could be hundreds of resource groups. Also not every user has access to every resource group. Querying at the subscription level scope would have been ideal. It appears like a bug to me in the forecast API since the same POST body when queried to get the actual spend using the query API does group results by resource group

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

The dataset documentation for query and forecast API is the same

0 Votes 0 ·

anonymous user It’s not a bug. Forecast does not support grouping/Group by as a feature.

Thanks for bringing this to our attention, we will be changing our swagger docs to address this.

Feel free to write back if you have any other question.


If the response helped, do "Accept Answer" and up-vote it

0 Votes 0 ·
AssafL-8253 avatar image
0 Votes"
AssafL-8253 answered VinayakNaik-8841 edited

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?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have similar issue,

Request

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

Output:

{
"error": {
"code": "UnexpectedColumns",
"message": "Can't calculate 'forecastTo' based on billing period - unexpected response columns:\nExpected: [PreTaxCost (Number)),UsageDate (Number)),BillingPeriod (String)),Currency (String))]\nActual: [UsageDate (Number)),BillingPeriod (String)),Currency (String))]"
}
}

Any idea on the above error ?

1 Vote 1 ·