Create and Manage Exported Data from Azure Cost Management
If you read the Cost Analysis tutorial, then you’re familiar with manually downloading your Cost Management data. However, you can create a recurring task that automatically exports your Cost Management data to Azure storage on a daily, weekly, or monthly basis. Exported data is in CSV format and it contains all the information that Cost Management collects. You can then use the exported data in Azure storage with external systems and combine it with your own custom data. And you can use your exported data in an external system like a dashboard or other financial system.
Watch the How to schedule exports to storage with Azure Cost Management video about creating a scheduled export of your Azure cost data to Azure Storage. To watch other videos, visit the Azure Cost Management YouTube channel.
The examples in this tutorial walk you through exporting your cost management data and then verify that the data was successfully exported.
In this tutorial, you will learn how to:
- Create a daily export
- Verify that data is collected
Prerequisites
Data export is available for various Azure account types, including Enterprise Agreement (EA) and Microsoft Customer Agreement customers. To view the full list of supported account types, see Understand Azure Cost Management data. The following Azure permissions, or scopes, are supported per subscription for data export by user and group. For more information about scopes, see Understand and work with scopes.
- Owner - Can create, modify, or delete scheduled exports for a subscription.
- Contributor - Can create, modify, or delete their own scheduled exports. Can modify the name of scheduled exports created by others.
- Reader - Can schedule exports that they have permission to.
- For more information about scopes, including access needed to configure exports for Enterprise Agreement and Microsoft Customer agreement scopes, see Understand and work with scopes.
For Azure Storage accounts:
- Write permissions are required to change the configured storage account, independent of permissions on the export.
- Your Azure storage account must be configured for blob or file storage.
- Don’t configure exports to a storage container when configured as a destination in an object replication rule.
- To export to storage accounts with configured firewalls, you need other privileges on the storage account. The other privileges are only required during export creation or modification. They are:
- Owner role on the storage account. Or
- Any custom role with
Microsoft.Authorization/roleAssignments/write
andMicrosoft.Authorization/permissions/read
permissions. Additionally, ensure that you enable Allow trusted Azure service access to the storage account when you configure the firewall. If you want to use the Exports REST API to generate exports to a storage account located behind a firewall, use the API version 2023-08-01 or later version. All newer API versions continue to support exports behind the firewall.
- The storage account configuration must have the Permitted scope for copy operations (preview) option set to From any storage account. :::image type=“content” source="./media/tutorial-export-acm-data/permitted-scope-copy-operations.png" alt-text=“Screenshot showing From any storage account option set.” lightbox="./media/tutorial-export-acm-data/permitted-scope-copy-operations.png" :::
If you have a new subscription, you can’t immediately use Azure Cost Management features. It might take up to 48 hours before you can use all Azure Cost Management features.
Sign in to Azure
Sign in to the Azure portal at https://portal.azure.com.
Create a daily export
Portal
To create or view a data export or to schedule an export, choose a scope in the Azure portal and select Cost analysis in the menu. For example, navigate to Subscriptions, select a subscription from the list, and then select Cost analysis in the menu. At the top of the Cost analysis page, select Configure subscription, then Exports.
[!NOTE]
- Besides subscriptions, you can create exports on resource groups, management groups, departments, and enrollments. For more information about scopes, see Understand and work with scopes.
- When you’re signed in as a partner at the billing account scope or on a customer’s tenant, you can export data to an Azure Storage account that’s linked to your partner storage account. However, you must have an active subscription in your CSP tenant.
- Select Create
- For Export details, make a selection:
- Type a name for export
- Daily export of month-to-date costs - Provides a new export file daily for your month-to-date costs. The latest data is aggregated from previous daily exports.
- Weekly export of cost for the last seven days - Creates a weekly export of your costs for the past seven days from the selected start date of your export.
- Monthly export of last month’s costs - Provides you with an export of your last month’s costs compared to the current month that you create the export. Afterward, the schedule runs an export on the fifth day of every new month with your previous months costs.
- One-time export - Allows you to choose a date range for historical data to export to Azure blob storage. You can export a maximum of 90 days of historical costs from the day you choose. This export runs immediately and is available in your storage account within two hours. Depending on your export type, either choose a start date, or choose a From and To date.
- Specify the subscription for your Azure storage account, then select a resource group or create a new one.
- Select the storage account name or create a new one.
- Select the location (Azure region).
- Specify the storage container and the directory path that you’d like the export file to go to. :::image type=“content” source="./media/tutorial-export-acm-data/basics_exports.png" alt-text=“Screenshot showing the New export page where you configure an export.” lightbox="./media/tutorial-export-acm-data/basics_exports.png":::
- Review your export details and select Create.
Your new export appears in the list of exports. By default, new exports are enabled. If you want to disable or delete a scheduled export, select any item in the list, and then select either Disable or Delete.
Initially, it can take 12-24 hours before the export runs. However, it can take up longer before data is shown in exported files.
Azure CLI
When you create an export programmatically, you must manually register the Microsoft.CostManagementExports
resource provider with the subscription where the storage account resides. Registration happens automatically when you create the export using the Azure portal. For more information about how to register resource providers, see Register resource provider.
Start by preparing your environment for the Azure CLI:
[!INCLUDE azure-cli-prepare-your-environment-no-header.md]
-
After you sign in, to see your current exports, use the az costmanagement export list command:
az costmanagement export list --scope "subscriptions/00000000-0000-0000-0000-000000000000"
[!NOTE]
- Besides subscriptions, you can create exports for resource groups and management groups. For more information about scopes, see Understand and work with scopes.
- When you’re signed in as a partner at the billing account scope or on a customer’s tenant, you can export data to an Azure Storage account that’s linked to your partner storage account. However, you must have an active subscription in your CSP tenant.
-
Create a resource group or use an existing resource group. To create a resource group, use the az group create command:
az group create --name TreyNetwork --location "East US"
-
Create a storage account to receive the exports or use an existing storage account. To create a storage account, use the az storage account create command:
az storage account create --resource-group TreyNetwork --name cmdemo
-
Run the az costmanagement export create command to create the export:
az costmanagement export create --name DemoExport --type ActualCost \ --scope "subscriptions/00000000-0000-0000-0000-000000000000" \ --storage-account-id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/TreyNetwork/providers/Microsoft.Storage/storageAccounts/cmdemo \ --storage-container democontainer --timeframe MonthToDate --recurrence Daily \ --recurrence-period from="2020-06-01T00:00:00Z" to="2020-10-31T00:00:00Z" \ --schedule-status Active --storage-directory demodirectory
For the
--type
parameter, you can chooseActualCost
,AmortizedCost
, orUsage
.This example uses
MonthToDate
. The export creates an export file daily for your month-to-date costs. The latest data is aggregated from previous daily exports this month. -
To see the details of your export operation, use the az costmanagement export show command:
az costmanagement export show --name DemoExport \ --scope "subscriptions/00000000-0000-0000-0000-000000000000"
-
Update an export by using the az costmanagement export update command:
az costmanagement export update --name DemoExport \ --scope "subscriptions/00000000-0000-0000-0000-000000000000" --storage-directory demodirectory02
This example changes the output directory.
[!NOTE] Initially, it can take 12-24 hours before the export runs. However, it can take longer before data is shown in exported files.
You can delete an export by using the az costmanagement export delete command:
az costmanagement export delete --name DemoExport --scope "subscriptions/00000000-0000-0000-0000-000000000000"
Azure PowerShell
When you create an export programmatically, you must manually register the Microsoft.CostManagementExports
resource provider with the subscription where the storage account resides. Registration happens automatically when you create the export using the Azure portal. For more information about how to register resource providers, see Register resource provider.
Start by preparing your environment for Azure PowerShell:
[!INCLUDE azure-powershell-requirements-no-header.md]
[!IMPORTANT] While the Az.CostManagement PowerShell module is in preview, you must install it separately using the
Install-Module
cmdlet. After this PowerShell module becomes generally available, it will be part of future Az PowerShell module releases and available by default from within Azure Cloud Shell.
Install-Module -Name Az.CostManagement
-
After you sign in, to see your current exports, use the Get-AzCostManagementExport cmdlet:
Get-AzCostManagementExport -Scope 'subscriptions/00000000-0000-0000-0000-000000000000'
[!NOTE]
- Besides subscriptions, you can create exports for resource groups and management groups. For more information about scopes, see Understand and work with scopes.
- When you’re signed in as a partner at the billing account scope or on a customer’s tenant, you can export data to an Azure Storage account that’s linked to your partner storage account. However, you must have an active subscription in your CSP tenant.
-
Create a resource group or use an existing resource group. To create a resource group, use the New-AzResourceGroup cmdlet:
New-AzResourceGroup -Name TreyNetwork -Location eastus
-
Create a storage account to receive the exports or use an existing storage account. To create a storage account, use the New-AzStorageAccount cmdlet:
New-AzStorageAccount -ResourceGroupName TreyNetwork -AccountName cmdemo -SkuName Standard_RAGRS -Location eastus
-
Run the New-AzCostManagementExport cmdlet to create the export:
$Params = @{ Name = 'DemoExport' DefinitionType = 'ActualCost' Scope = 'subscriptions/00000000-0000-0000-0000-000000000000' DestinationResourceId = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/treynetwork/providers/Microsoft.Storage/storageAccounts/cmdemo' DestinationContainer = 'democontainer' DefinitionTimeframe = 'MonthToDate' ScheduleRecurrence = 'Daily' RecurrencePeriodFrom = '2020-06-01T00:00:00Z' RecurrencePeriodTo = '2020-10-31T00:00:00Z' ScheduleStatus = 'Active' DestinationRootFolderPath = 'demodirectory' Format = 'Csv' } New-AzCostManagementExport @Params
For the DefinitionType parameter, you can choose
ActualCost
,AmortizedCost
, orUsage
.This example uses
MonthToDate
. The export creates an export file daily for your month-to-date costs. The latest data is aggregated from previous daily exports this month. -
To see the details of your export operation, use the
Get-AzCostManagementExport
cm