Manage Azure costs with automation - Microsoft Cost Management (2023)

  • Article
  • 12 minutes to read

You can use Cost Management automation to build a custom set of solutions to retrieve and manage cost data. This article covers common scenarios for Cost Management automation and options available based on your situation. If you want to develop using APIs, common API request examples and presented to help accelerate your development process.

Automate cost data retrieval for offline analysis

You might need to download your Azure cost data to merge it with other datasets. Or you might need to integrate cost data into your own systems. There are different options available depending on the amount of data involved. You must have Cost Management permissions at the appropriate scope to use APIs and tools in any case. For more information, see Assign access to data.

Suggestions for handling large datasets

If your organization has a large Azure presence across many resources or subscriptions, you'll have a large amount of usage details data. Excel often can't load such large files. In this situation, we recommend the following options:

Power BI

Power BI is used to ingest and handle large amounts of data. If you're an Enterprise Agreement customer, you can use the Power BI template app to analyze costs for your billing account. The report contains key views used by customers. For more information, see Analyze Azure costs with the Power BI template app.

Power BI data connector

If you want to analyze your data daily, we recommend using the Power BI data connector to get data for detailed analysis. Any reports that you create are kept up to date by the connector as more costs accrue.

Cost Management exports

You might not need to analyze the data daily. If so, consider using Cost Management's Exports feature to schedule data exports to an Azure Storage account. Then you can load the data into Power BI as needed, or analyze it in Excel if the file is small enough. Exports are available in the Azure portal or you can configure exports with the Exports API.

Usage Details API

(Video) How to manage and control your cloud costs with Azure Cost Management

Consider using the Usage Details API if you have a small cost data set. Here are recommended best practices:

  • If you want to get the latest cost data, we recommend that you query at most once per day. Reports are refreshed every four hours. If you call more frequently, you'll receive identical data.
  • Once you download your cost data for historical invoices, the charges won't change unless you're explicitly notified. We recommend caching your cost data in a queryable store on to prevent repeated calls for identical data.
  • Chunk your calls into small date ranges to get more manageable files that you can download. For example, we recommend chunking by day or by week if you have large Azure usage files month-to-month.
  • If you have scopes with a large amount of usage data (for example a Billing Account), consider placing multiple calls to child scopes so you get more manageable files that you can download.
  • If your dataset is more than 2 GB month-to-month, consider using exports as a more scalable solution.

Automate retrieval with Usage Details API

The Usage Details API provides an easy way to get raw, unaggregated cost data that corresponds to your Azure bill. The API is useful when your organization needs a programmatic data retrieval solution. Consider using the API if you're looking to analyze smaller cost data sets. However, you should use other solutions identified previously if you have larger datasets. The data in Usage Details is provided on a per meter basis, per day. It's used when calculating your monthly bill. The general availability (GA) version of the APIs is 2019-10-01. Use 2019-04-01-preview to access the preview version for reservation and Azure Marketplace purchases with the APIs.

If you want to get large amounts of exported data regularly, see Retrieve large cost datasets recurringly with exports.

Usage Details API suggestions

Request schedule

We recommend that you make no more than one request to the Usage Details API per day. For more information about how often cost data is refreshed and how rounding is handled, see Understand cost management data.

Target top-level scopes without filtering

Use the API to get all the data you need at the highest-level scope available. Wait until all needed data is ingested before doing any filtering, grouping, or aggregated analysis. The API is optimized specifically to provide large amounts of unaggregated raw cost data. To learn more about scopes available in Cost Management, see Understand and work with scopes. Once you've downloaded the needed data for a scope, use Excel to analyze data further with filters and pivot tables.

Notes about pricing

If you want to reconcile usage and charges with your price sheet or invoice, note the following information.

Price Sheet price behavior - The prices shown on the price sheet are the prices that you receive from Azure. They're scaled to a specific unit of measure. Unfortunately, the unit of measure doesn't always align to the unit of measure at which the actual resource usage and charges are emitted.

Usage Details price behavior - Usage files show scaled information that may not match precisely with the price sheet. Specifically:

  • Unit Price - The price is scaled to match the unit of measure at which the charges are actually emitted by Azure resources. If scaling occurs, then the price won't match the price seen in the Price Sheet.
  • Unit of Measure - Represents the unit of measure at which charges are actually emitted by Azure resources.
  • Effective Price / Resource Rate - The price represents the actual rate that you end up paying per unit, after discounts are taken into account. It's the price that should be used with the Quantity to do Price * Quantity calculations to reconcile charges. The price takes into account the following scenarios and the scaled unit price that's also present in the files. As a result, it might differ from the scaled unit price.
    • Tiered pricing - For example: $10 for the first 100 units, $8 for the next 100 units.
    • Included quantity - For example: The first 100 units are free and then $10 per unit.
    • Reservations
    • Rounding that occurs during calculation – Rounding takes into account the consumed quantity, tiered/included quantity pricing, and the scaled unit price.

A single resource might have multiple records for a single day

Azure resource providers emit usage and charges to the billing system and populate the Additional Info field of the usage records. Occasionally, resource providers might emit usage for a given day and stamp the records with different datacenters in the Additional Info field of the usage records. It can cause multiple records for a meter/resource to be present in your usage file for a single day. In that situation, you aren't overcharged. The multiple records represent the full cost of the meter for the resource on that day.

Example Usage Details API requests

The following example requests are used by Microsoft customers to address common scenarios that you might come across.

(Video) Azure Cost Management Tutorial | Analyzing and reacting to changes in billing

Get Usage Details for a scope during specific date range

The data that's returned by the request corresponds to the date when the usage was received by the billing system. It might include costs from multiple invoices. The call to use varies by your subscription type.

For legacy customers with an Enterprise Agreement (EA) or a pay-as-you-go subscription, use the following call:

GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?$filter=properties%2FusageStart%20ge%20'2020-02-01'%20and%20properties%2FusageEnd%20le%20'2020-02-29'&$top=1000&api-version=2019-10-01

For modern customers with a Microsoft Customer Agreement, use the following call:

GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?startDate=2020-08-01&endDate=2020-08-05&$top=1000&api-version=2019-10-01

Note

The $filter parameter isn't supported by Microsoft Customer Agreements.

Get amortized cost details

If you need actual costs to show purchases as they're accrued, change the metric to ActualCost in the following request. To use amortized and actual costs, you must use the 2019-04-01-preview version. The current API version works the same as the 2019-10-01 version, except for the new type/metric attribute and changed property names. If you have a Microsoft Customer Agreement, your filters are startDate and endDate in the following example.

GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?metric=AmortizedCost&$filter=properties/usageStart+ge+'2019-04-01'+AND+properties/usageEnd+le+'2019-04-30'&api-version=2019-04-01-preview

Automate alerts and actions with budgets

There are two critical components to maximizing the value of your investment in the cloud. One is automatic budget creation. The other is configuring cost-based orchestration in response to budget alerts. There are different ways to automate Azure budget creation. Various alert responses happen when your configured alert thresholds are exceeded.

The following sections cover available options and provide sample API requests to get you started with budget automation.

How costs are evaluated against your budget threshold

Your costs are evaluated against your budget threshold once per day. When you create a new budget or at your budget reset day, the costs compared to the threshold will be zero/null because the evaluation might not have occurred.

When Azure detects that your costs have crossed the threshold, a notification is triggered within the hour of the detecting period.

View your current cost

To view your current costs, you need to make a GET call using the Query API.

(Video) Azure Cost Management Overview

A GET call to the Budgets API won't return the current costs shown in Cost Analysis. Instead, the call returns your last evaluated cost.

Automate budget creation

You can automate budget creation using the Budgets API. You can also create a budget with a budget template. Templates are an easy way for you to standardize Azure deployments while ensuring cost control is properly configured and enforced.

Supported locales for budget alert emails

With budgets, you're alerted when costs cross a set threshold. You can set up to five email recipients per budget. Recipients receive the email alerts within 24 hours of crossing the budget threshold. However, your recipient might need to receive an email in a different language. You can use the following language culture codes with the Budgets API. Set the culture code with the locale parameter similar to the following example.

{ "eTag": "\"1d681a8fc67f77a\"", "properties": { "timePeriod": { "startDate": "2020-07-24T00:00:00Z", "endDate": "2022-07-23T00:00:00Z" }, "timeGrain": "BillingMonth", "amount": 1, "currentSpend": { "amount": 0, "unit": "USD" }, "category": "Cost", "notifications": { "actual_GreaterThan_10_Percent": { "enabled": true, "operator": "GreaterThan", "threshold": 20, "locale": "en-us", "contactEmails": [ "user@contoso.com" ], "contactRoles": [], "contactGroups": [], "thresholdType": "Actual" } } }}

Languages supported by a culture code:

Culture codeLanguage
en-usEnglish (United States)
ja-jpJapanese (Japan)
zh-cnChinese (Simplified, China)
de-deGerman (Germany)
es-esSpanish (Spain, International)
fr-frFrench (France)
it-itItalian (Italy)
ko-krKorean (Korea)
pt-brPortuguese (Brazil)
ru-ruRussian (Russia)
zh-twChinese (Traditional, Taiwan)
cs-czCzech (Czech Republic)
pl-plPolish (Poland)
tr-trTurkish (Turkey)
da-dkDanish (Denmark)
en-gbEnglish (United Kingdom)
hu-huHungarian (Hungary)
nb-noNorwegian Bokmal (Norway)
nl-nlDutch (Netherlands)
pt-ptPortuguese (Portugal)
sv-seSwedish (Sweden)

Common Budgets API configurations

There are many ways to configure a budget in your Azure environment. Consider your scenario first and then identify the configuration options that enable it. Review the following options:

  • Time Grain - Represents the recurring period your budget uses to accrue and evaluate costs. The most common options are Monthly, Quarterly, and Annual.
  • Time Period - Represents how long your budget is valid. The budget actively monitors and alerts you only while it remains valid.
  • Notifications
    • Contact Emails – The email addresses receive alerts when a budget accrues costs and exceeds defined thresholds.
    • Contact Roles - All users who have a matching Azure role on the given scope receive email alerts with this option. For example, Subscription Owners could receive an alert for a budget created at the subscription scope.
    • Contact Groups - The budget calls the configured action groups when an alert threshold is exceeded.
  • Cost dimension filters - The same filtering you can do in Cost Analysis or the Query API can also be done on your budget. Use this filter to reduce the range of costs that you're monitoring with the budget.

After you've identified the budget creation options that meet your needs, create the budget using the API. The example below helps get you started with a common budget configuration.

Create a budget filtered to multiple resources and tags

Request URL: PUT https://management.azure.com/subscriptions/{SubscriptionId} /providers/Microsoft.Consumption/budgets/{BudgetName}/?api-version=2019-10-01

{ "eTag": "\"1d34d016a593709\"", "properties": { "category": "Cost", "amount": 100.65, "timeGrain": "Monthly", "timePeriod": { "startDate": "2017-10-01T00:00:00Z", "endDate": "2018-10-31T00:00:00Z" }, "filter": { "and": [ { "dimensions": { "name": "ResourceId", "operator": "In", "values": [ "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{meterName}", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{meterName}" ] } }, { "tags": { "name": "category", "operator": "In", "values": [ "Dev", "Prod" ] } }, { "tags": { "name": "department", "operator": "In", "values": [ "engineering", "sales" ] } } ] }, "notifications": { "Actual_GreaterThan_80_Percent": { "enabled": true, "operator": "GreaterThan", "threshold": 80, "contactEmails": [ "user1@contoso.com", "user2@contoso.com" ], "contactRoles": [ "Contributor", "Reader" ], "contactGroups": [ "/subscriptions/{subscriptionID}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName} ], "thresholdType": "Actual" } } }}

Configure cost-based orchestration for budget alerts

You can configure budgets to start automated actions using Azure Action Groups. To learn more about automating actions using budgets, see Automation with Azure Budgets.

Data latency and rate limits

We recommend that you call the APIs no more than once per day. Cost Management data is refreshed every four hours as new usage data is received from Azure resource providers. Calling more frequently doesn't provide more data. Instead, it creates increased load.

Query API query processing units

In addition to the existing rate limiting processes, the Query API also limits processing based on the cost of API calls. The cost of an API call is expressed as query processing units (QPUs). QPU is a performance currency, like Cosmos DB RUs. They abstract system resources like CPU and memory.

QPU calculation

Currently, one QPU is deducted for one month of data queried from the allotted quotas. This logic might change without notice.

(Video) Managing, reporting, and reducing your costs in Azure | Azure Friday

QPU factors

The following factor affects the number of QPUs consumed by an API request.

  • Date range, as the date range in the request increases, the number of QPUs consumed increases.

Other QPU factors might be added without notice.

QPU quotas

The following quotas are configured per tenant. Requests are throttled when any of the following quotas are exhausted.

  • 12 QPU per 10 seconds
  • 60 QPU per 1 min
  • 600 QPU per 1 hour

The quotas maybe be changed as needed and more quotas may be added.

Response headers

You can examine the response headers to track the number of QPUs consumed by an API request and number of QPUs remaining.

x-ms-ratelimit-microsoft.costmanagement-qpu-retry-after

Indicates the time to back-off in seconds. When a request is throttled with 429, back off for the time specified in this header before retrying the request.

x-ms-ratelimit-microsoft.costmanagement-qpu-consumed

QPUs consumed by an API call.

x-ms-ratelimit-microsoft.costmanagement-qpu-remaining

List of remaining quotas.

Next steps

  • Analyze Azure costs with the Power BI template app.
  • Create and manage exported data with Exports.
  • Learn more about the Usage Details API.

FAQs

How do you manage costs in Azure? ›

How Do I Enable Azure Cost Management?
  1. Access the Azure portal with an enterprise administrator account.
  2. From the menu, select Cost Management + Billing.
  3. Click Billing scopes and select your billing account.
  4. Click Settings, and select Policies from the menu.

Can you see the cost from Azure cost management per management group? ›

Users can view costs by navigating to Cost Management + Billing in the Azure portal list of services. Then, they can filter costs to the specific subscriptions and resource groups they need to report on.

Which of the following is a good practice to reduce costs in Azure? ›

High impact recommendations include: Buy an Azure savings plan to save money on a variety of compute services. Buy reserved virtual machine instances to save money over pay-as-you-go costs. Optimize virtual machine spend by resizing or shutting down underutilized instances.

How do I automate a cost report in Azure? ›

Login to Azure Portal and create a general purpose V2 storage account to export the reports in CSV format.
  1. Storage Account.
  2. Select Scope.
  3. Create Daily Report.
  4. Export Schedules.
  5. Storage Account Reports Folder.
  6. Daily Report Output.
Oct 27, 2020

What should you use to track the costs of Azure? ›

Azure Cost Management + Billing is the primary tool you'll use to analyze your usage and costs. It gives you multiple options to analyze your monthly charges for different Azure Monitor features and their projected cost over time.

What are the four 4 main processes of cost management? ›

The Four Steps in Project Cost Management. While cost management is viewed as a continuous process, it helps to split the function into four steps: resource planning, estimation, budgeting and control.

What does the Azure cost management tool do? ›

Azure Cost Management runs continuously after you enable it, monitoring your resources and generating continuous reports. You can analyze historic cloud usage patterns, identify expense trends, and predict future costs.

What are the 3 pricing models of Azure? ›

Azure Pricing Models

Microsoft offers three main ways to pay for Azure VMs and other cloud resources: pay as you go, reserved instances, and spot instances.

What are the main factors that affect Azure cost? ›

In this article:
  • Factors Affecting Azure Costs. Resource Type. Services. Location. Azure Billing Zones.
  • What is Azure Cost Management?
  • Additional Azure Cost Optimization Tools.
  • Advanced Cost Data Analysis in Azure. Power BI. Power BI Data Connector. Cost Management exports. Usage Details API. ...
  • Azure Cost Optimization with Spot.io.

What should be included in a cost management plan? ›

11 key elements of a cost management plan
  • Measurement units. The first section in a cost management plan is the units of measurement portion. ...
  • Location. ...
  • Earned value management. ...
  • Percent completion. ...
  • Control thresholds. ...
  • Precision levels. ...
  • Levels of accuracy. ...
  • Reporting formats.
Oct 8, 2021

How do you avoid charges in Azure? ›

Usage exceeds the limits of free services

If in a month, you only use 2 GB, the remaining 3 GB doesn't roll over to the next month. To avoid getting charged, keep your usage within the limits.

How do I not lose control over costs in Microsoft Azure? ›

Cost Management
  1. Consider the type of virtual machine you are using. For a D-series machine, ensure that the application or workload running actually needs that much power. ...
  2. Check resource groups for unused disks. ...
  3. Check how many databases are running in Azure SQL and confirm they are needed.

What are the 3 important services offered by Azure? ›

Top 10 Microsoft Azure Products and Services

Azure Virtual Machines. Azure Backup. Azure Cosmos DB. Azure Logic Apps.

What is the best way to automate reports? ›

Our Pick of the Best Options for Automated Reports
  1. Built-in reporting for your CRM and key apps.
  2. Google Analytics.
  3. Google Sheets.
  4. Google Data Studio.
  5. Supermetrics.
Oct 22, 2021

How do I automate Azure resources? ›

Open a new browser window, and sign in to the Azure portal. Open the Azure resource where you expect to find your automation task. Create an automation task with your exported template. Run the task.

How do you analyze cost in Azure? ›

In the Azure portal, navigate to cost analysis for your scope. For example: Cost Management + Billing > Cost Management > Cost analysis. Select your enrollment and then view your current accumulated costs.

Which tool helps you estimate the cost you will increase or Azure? ›

Azure Cost Calculator is a free cost management tool that can help you estimate your cloud costs for new Azure deployments, or variations of your existing workloads.

What tools can be used to manage Azure budgets and billing accounts? ›

Azure Cost Management has several APIs available, giving you programmatic access to cost and usage data for your Azure resources.
...
API Reference
  • Azure Consumption Python SDK.
  • Azure Consumption CLI.
  • Azure Consumption . NET SDK.
  • Azure Consumption NodeJS SDK.
  • Azure Consumption Ruby SDK.

What are the 5 tools and techniques of cost control? ›

Here are five cost control methods that allow a company to maintain and track its overall costs:
  • Planning the budget properly. ...
  • Monitoring all expenses using checkpoints. ...
  • Using change control systems. ...
  • Having time management. ...
  • Tracking earned value.
Apr 13, 2021

What are the 5 functions of cost management? ›

Planning, communication, motivation, appraisal, and decision-making are the features that make managing costs an important business procedure. Resource allocation, cost estimation, cost budgeting, and cost control are the major functions of the cost management process.

What are two Azure management tools? ›

In addition to the graphical user interface offered at the Azure Portal, we have the ability to manage and interact with Azure via Azure Powershell, Azure Command Line Interface (CLI), Azure Cloud Shell, and the Azure Mobile Application available on iOS and Android platforms.

What are Azure 4 management scopes? ›

Scope levels

In Azure, you can specify a scope at four levels: management group, subscription, resource group, and resource. Scopes are structured in a parent-child relationship. Each level of hierarchy makes the scope more specific. You can assign roles at any of these levels of scope.

What is the purpose of cost management? ›

Cost management is the process of planning and controlling the costs associated with running a business. It includes collecting, analyzing and reporting cost information to more effectively budget, forecast and monitor costs.

What are the 3 basic pricing strategies? ›

The three most common pricing strategies are:
  • Value based pricing - Price based on it's perceived worth.
  • Competitor based pricing - Price based on competitors pricing.
  • Cost plus pricing - Price based on cost of goods or services plus a markup.
Nov 8, 2021

What are the three levels of price management? ›

Pricing can be approached at three levels: the industry, market, and transaction level.

What are the three key factors in defining cost on cloud? ›

Capacity, transactions, Networking are the three main key factors in defining cost on cloud storage.

What are the challenges with Microsoft Azure? ›

5 Microsoft Azure Challenges
  • Drastic infrastructure changes.
  • On-premise and Azure overlap.
  • Lack of options for every solution.
  • Understanding licensing.
  • Service feature differences.
Feb 24, 2020

What are the important drawbacks of using Microsoft Azure? ›

Data Transfer

This is not unique to Azure as all of the large cloud services like AWS and Google do this same gouging of their customer base. This separate fee for in and out data can prove quite costly for large companies, so you should be aware of this to avoid any surprises.

What are 3 ways a project manager controls costs? ›

Here are the four main processes of project cost control:
  • Measure differences from baseline budget. ...
  • Forecast final costs. ...
  • Determine possible corrective actions. ...
  • Implement and evaluate corrective actions.
May 25, 2021

What is cost management give me an example? ›

Cost management plans keep all project costs in one place, including direct and indirect costs. A project manager will track these costs to ensure there are no budget overruns. A cost management plan example could be the budget for a home improvement project.

What are the three benefits of cost management? ›

4 Benefits of Cost-Control Management
  • Lower Expenses. The main benefit of putting cost controls in place is lowering your company's overall expenses. ...
  • Gain Operational Efficiency. ...
  • Realize Procurement Effectiveness. ...
  • Streamline Technology.
Nov 1, 2022

How do I reduce my cost on my Azure Storage account? ›

You can reduce cost by placing blob data into the most cost-effective access tier. Place frequently accessed data in a hot tier, less frequent in a cold or archive tier. Use Premium storage for workloads with high transaction volumes or workloads where latency is critical.

How do you control the cost of an event? ›

8 Ways to Cut Event Costs
  1. The Venue. Finding an affordable venue that meets all your requirements can be a challenge. ...
  2. Equipment & Facilities. ...
  3. Multiple Quotes & Negotiating. ...
  4. Flexibility on dates. ...
  5. Extra Costs. ...
  6. Use Social media. ...
  7. Volunteers. ...
  8. Event sponsorship.

Videos

1. Microsoft Azure Fundamentals: Cost Management in Azure
(Techquest Learning Point)
2. Ask the Expert: How to manage your cloud costs in Azure Cost Management + Billing​ | ATE-DB112-R1
(Microsoft Ignite)
3. Working with Azure Cost Management APIs | INT175B
(Microsoft Developer)
4. Azure Cost Management - Exports
(Hello World)
5. Take Control of Costs with Azure Cost Management
(Cloud Lunch and Learn)
6. Azure Cost Management
(Kirby's SQL Talk)
Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated: 03/12/2023

Views: 5951

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.