Cost management GRAPH API: TheLastBillingMonth returns lastmonth amount

Blaise Lugeon 26 Reputation points
2021-08-20T09:49:23.503+00:00

Hello,

I need to extract the cost of the last Azure invoice per resource group.
I use the Graph API following https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage

In timeframe param, the use of "TheLastMonth" returns the exact value of the last month => ok.
If I use instead "TheLastBillingMonth", I still get the same value [of the last month] instead of the last billing period which I expect.

See below the code I use... What's wrong in my understanding?

Thanks!


scope = 'subscriptions/' + subscription_id
base_url = 'https://management.azure.com/' + scope +'/providers/Microsoft.CostManagement/query?api-version=2019-11-01'

request header

headers = {'Authorization' : 'Bearer ' + access_token, 'Content-type' : 'application/json'}

body = {  
    "type": "Usage",  
    **"timeframe": "TheLastBillingMonth",**  
    "dataset": {  
        "granularity": "None",  
        "aggregation": {  
            "totalCost": {  
            "name": "PreTaxCost",  
            "function": "Sum"  
            }  
        },  
        "grouping": [  
            {  
                "type": "Dimension",  
                "name": "ResourceGroup"  
            }  
        ]  
    }  
}  
Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
3,582 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SadiqhAhmed-MSFT 49,326 Reputation points Microsoft Employee Moderator
    2021-08-24T06:11:08.623+00:00

    Hello anonymous user - Thank you for your post and I apologize for the delayed response!

    If the billing cycle of your subscription is from 1st to last of the month, then the value returned by TheLastMonth and TheLastBillingMonth will be equal as we are looking at the same timeframe.

    You can confirm the billing cycle from the subscription overview blade. My subscription billing cycle is 8/1 to 8/31 which means if I call last month or last billing month: both will be pointing to 7/1 to 7/30 and will return the same value:

    125827-image.png

    Hope this helps!

    ---------------------------------------------------------------------------------------------------------------

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.