How to automate creation of custom, view under Azure Cost Analysis

Sanjay Nipane 21 Reputation points
2023-07-11T14:23:43.4133333+00:00

Hi,

Under 'Cost management' section, we can create a custom view under 'Cost Analysis'. Through portal, this can be done easily.

I want to automate this functionality of creating a view under Cost analysis to show previous month cost.

Since I want to automate this process for different subscription so requesting to advice if we have any solution for this.

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
3,578 questions
{count} votes

Accepted answer
  1. SadiqhAhmed-MSFT 49,326 Reputation points Microsoft Employee Moderator
    2023-07-11T14:56:44.9633333+00:00

    Hello @Sanjay Nipane Thank you for contacting on Microsoft Q&A platform. Happy to help!

    As I understand your requirement to automate creation of custom view under Azure Cost Analysis for multiple subscriptions. You can use Cost Management Create/Update views API to programmatically create Cost Management Views: 

    https://learn.microsoft.com/en-us/rest/api/cost-management/views/create-or-update-by-scope?tabs=HTTP 

    Example payload which you can customize:

    {
        "properties": {
            "currency": "USD",
            "dateRange": "LastMonth",
            "query": {
                "type": "ActualCost",
                "dataSet": {
                    "granularity": "Daily",
                    "aggregation": {
                        "totalCost": {
                            "name": "Cost",
                            "function": "Sum"
                        },
                        "totalCostUSD": {
                            "name": "CostUSD",
                            "function": "Sum"
                        }
                    },
                    "sorting": [
                        {
                            "direction": "ascending",
                            "name": "UsageDate"
                        }
                    ],
                    "grouping": [
                        {
                            "type": "Dimension",
                            "name": "ServiceName"
                        }
                    ]
                },
                "timeframe": "None"
            },
            "chart": "Area",
            "accumulated": "true",
            "pivots": [
                {
                    "type": "Dimension",
                    "name": "ServiceName"
                },
                {
                    "type": "Dimension",
                    "name": "ResourceLocation"
                },
                {
                    "type": "Dimension",
                    "name": "ResourceGroupName"
                }
            ],
            "scope": "subscriptions/{SubscriptionGUID}",
            "kpis": [
                {
                    "type": "Forecast",
                    "enabled": true
                }
            ],
            "displayName": "{ViewName}"
        }
    }
    
    
    

    Hope this helps!


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

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.