Bird
Raised Fist0
Azurecloud~5 mins

Azure Cost Analysis tool - Commands & Configuration

Choose your learning style10 modes available
Introduction
Managing cloud spending can be confusing. Azure Cost Analysis helps you see where your money goes in Azure. It shows detailed reports of your cloud costs so you can control your budget.
When you want to check how much your Azure resources cost this month.
When you need to find which service or project is using the most money.
When you want to set a budget and track if you are close to it.
When you want to see cost trends over time to plan better.
When you want to export cost data for reports or further analysis.
Commands
Log in to your Azure account to access your subscriptions and resources.
Terminal
az login
Expected OutputExpected
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCD1234 to authenticate. You have logged in. Now let us find all the subscriptions to which you have access...
Run a cost query for the current month to see daily usage costs for your subscription.
Terminal
az costmanagement query --type Usage --timeframe MonthToDate --dataset-configuration '{"granularity":"Daily"}' --scope /subscriptions/00000000-0000-0000-0000-000000000000
Expected OutputExpected
{"columns":[{"name":"Date","type":"DateTime"},{"name":"Cost","type":"Number"}],"rows":[["2024-06-01",12.34],["2024-06-02",15.67],["2024-06-03",10.89]]}
→
--type - Specifies the type of cost data to query, here usage costs.
→
--timeframe - Defines the time range for the cost data.
→
--scope - Sets the subscription or resource group to analyze.
Create a cost export to save monthly cost data automatically to a storage account for later review.
Terminal
az costmanagement export create --name MonthlyCostReport --type Usage --timeframe MonthToDate --storage-account mycoststorage --container costreports --scope /subscriptions/00000000-0000-0000-0000-000000000000
Expected OutputExpected
{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/exports/MonthlyCostReport","name":"MonthlyCostReport","type":"Microsoft.CostManagement/exports","properties":{"exportType":"Usage","timeframe":"MonthToDate","storageAccountId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mycoststorage","container":"costreports"}}
→
--name - Names the export job.
→
--storage-account - Specifies where to save the exported cost data.
→
--container - Defines the storage container for the export files.
Check the details and status of the cost export you created.
Terminal
az costmanagement export show --name MonthlyCostReport --scope /subscriptions/00000000-0000-0000-0000-000000000000
Expected OutputExpected
{"name":"MonthlyCostReport","properties":{"exportType":"Usage","timeframe":"MonthToDate","status":"Succeeded","storageAccountId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mycoststorage","container":"costreports"}}
Key Concept

If you remember nothing else from this pattern, remember: Azure Cost Analysis lets you see and control your cloud spending by showing detailed cost reports and exporting data for review.

Common Mistakes
Not logging in with 'az login' before running cost commands.
Commands fail because Azure CLI needs authentication to access your data.
Always run 'az login' first and complete the sign-in process.
Using incorrect subscription ID in the --scope flag.
The command cannot find your subscription and returns an error or empty data.
Use 'az account show' to get your current subscription ID and use it exactly.
Not creating a storage account or container before setting up cost export.
Export creation fails because the destination does not exist.
Create a storage account and container in Azure portal or CLI before running export commands.
Summary
Use 'az login' to authenticate your Azure CLI session.
Run 'az costmanagement query' to get detailed cost data for your subscription.
Create cost exports with 'az costmanagement export create' to save reports automatically.
Check export status with 'az costmanagement export show' to ensure your data is saved.

Practice

(1/5)
1. What is the main purpose of the Azure Cost Analysis tool?
easy
A. To monitor network traffic
B. To create virtual machines
C. To track and understand your cloud spending
D. To manage user access permissions

Solution

  1. Step 1: Understand the tool's function

    The Azure Cost Analysis tool is designed to help users see how much they spend on cloud services.
  2. Step 2: Compare options with tool purpose

    The remaining options relate to other Azure services like VM creation, network monitoring, or access management, not cost tracking.
  3. Final Answer:

    To track and understand your cloud spending -> Option C
  4. Quick Check:

    Cost Analysis = Spending tracking [OK]
Hint: Cost Analysis = Understand cloud spending fast [OK]
Common Mistakes:
  • Confusing cost analysis with resource creation
  • Mixing cost tracking with security management
  • Thinking it monitors network or performance
2. Which of the following is the correct way to filter costs by resource group in Azure Cost Analysis?
easy
A. Create a new virtual machine in the resource group
B. Select the 'Resource Group' filter and choose the desired group
C. Use the Azure CLI to list resource groups
D. Enable diagnostic logs on the resource group

Solution

  1. Step 1: Identify filtering method in Cost Analysis

    Azure Cost Analysis allows filtering by selecting filters like 'Resource Group' from the interface.
  2. Step 2: Eliminate unrelated options

    Creating VMs, using CLI to list groups, or enabling logs relate to resource management, not filtering costs in the UI.
  3. Final Answer:

    Select the 'Resource Group' filter and choose the desired group -> Option B
  4. Quick Check:

    Filter by resource group = Select filter [OK]
Hint: Use built-in filters to narrow cost views [OK]
Common Mistakes:
  • Confusing filtering with resource creation
  • Using CLI commands instead of UI filters
  • Thinking logs filter costs
3. You apply a filter for the last 7 days in Azure Cost Analysis and see a chart showing daily costs. What does the chart represent?
medium
A. The total cost for each day in the last 7 days
B. The number of virtual machines created each day
C. The network traffic volume per day
D. The number of users logged in each day

Solution

  1. Step 1: Understand the filter effect

    Filtering by last 7 days in Cost Analysis shows cost data for each day in that period.
  2. Step 2: Interpret the chart meaning

    The chart displays daily spending totals, not resource counts or traffic.
  3. Final Answer:

    The total cost for each day in the last 7 days -> Option A
  4. Quick Check:

    Filter by date = daily cost chart [OK]
Hint: Date filter shows daily cost totals [OK]
Common Mistakes:
  • Confusing cost with resource counts
  • Assuming charts show network or user data
  • Ignoring the filter's time range effect
4. You tried to filter costs by a tag in Azure Cost Analysis but see no results. What is the most likely reason?
medium
A. You need to restart the Azure portal
B. The Azure subscription is expired
C. The Cost Analysis tool is offline
D. The resources do not have the specified tag applied

Solution

  1. Step 1: Check tag usage

    Filtering by tag shows results only if resources have that tag assigned.
  2. Step 2: Rule out unrelated causes

    Subscription expiry, tool offline, or portal restart do not cause empty tag filter results.
  3. Final Answer:

    The resources do not have the specified tag applied -> Option D
  4. Quick Check:

    No tag results = missing tag on resources [OK]
Hint: No results? Check if tag exists on resources [OK]
Common Mistakes:
  • Assuming tool or portal is broken
  • Blaming subscription status incorrectly
  • Not verifying tag presence on resources
5. Your company wants to reduce unexpected cloud costs. How can you use Azure Cost Analysis to help achieve this?
hard
A. Set up regular cost reviews with filters for departments and resource types
B. Delete all virtual machines immediately
C. Disable all Azure services to stop billing
D. Ignore cost reports and focus on performance

Solution

  1. Step 1: Identify cost management strategy

    Regular reviews with filters help spot high spending areas and control budgets.
  2. Step 2: Evaluate options for cost control

    Deleting all VMs or disabling services is impractical; ignoring reports misses cost issues.
  3. Final Answer:

    Set up regular cost reviews with filters for departments and resource types -> Option A
  4. Quick Check:

    Regular filtered reviews = cost control [OK]
Hint: Review costs regularly by department and resource [OK]
Common Mistakes:
  • Thinking deleting all resources is a solution
  • Ignoring cost data leads to surprises
  • Disabling services stops usage but is not practical
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard