Azure Cost analysis for a specific group of resources

This article is about how to create a proper cost analysis in Azure for a group of resources possess the same tag
 01/22/2021 19:11:48
 Varga Gábor

This article has been created to demonstrate how a proper Cost analysis can be created within Azure if you would like to follow the costs of a specific group of resources only. By default Azure cost management always shows only the cost of whole subscription. Of course, there are possibilities to add some specific filters e.g.: resource type, resource group, name etc.

Now I will show you how you can create a permanent Cost analysis view with an automated solution to add the new resources to the cost analysis solution.

Create the Cost Analysis view

This example will have Tag filtering in the Cost analysis. This is a very easy to configure.

  1. Login to Azure portal
  2. Open Cost Management + Billing and navigate to Cost analysis. This page always shows the monthly cost of all resources within the selected subscription in an Accumulated view. This is the default.

  3. To filter the cost information, you can use the filter button at the top of page
  4. In this example I am using filter tag name "costanalysis" and tag value "dynamics" for filter only a specific group of resources (related to MS Dynamics resources). This was a requirement for one of my customers.
  5. When this filter has been configured, the chart is updating automatically and Azure portal displays the cost information calculated from the filtered resources only.
  6. In order to avoid these manual filtering all the time, it is possible to save this view in a list and it just need to be opened in the future without any manual filtering. Just click to Save as button a the top and give some name of the View. If you select the field "Make this view private" then the view will appear only for you. If you leave it empty, the view will be a shared view therefore everyone who has permission reading the costs will be able to select this view.
  7. If the save has been done, you can simply choose the new View from the list of Views. In this example I have created it as a shared view therefore everyone from the customer (who has proper rights) can view the content.
  8. Now it is displaying the cost within our permanent View
  9. It is possible to save the cost information as an excel, CSV or PNG file using the Download button at the top. I suggest you to use the PNG file export as per it is showing the data and the chart itself properly.

Resource tagging

In order to the Cost analysis solution above work fine, it is required to tag the resources properly. There are two ways for this:

  • Manual tagging: resources can be tagged manually either using portal (open resource, navigate to Tags and set the tag name and value) or using the following powershell command: New-AzTag -ResourceId <ResourceId> -Tag @{"<TagName>"="<TagValue>"}
  • Automatic tagging: this can be achieved with an Azure policy attached to the Subscription. (see details below)