Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Analyze and reduce Azure cloud costs by right-sizing resources, reservations, and spending policies
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
cost-query/examples.md
1# Cost Management Query Examples23Common query patterns with request bodies. Use the [SKILL.md workflow](../SKILL.md) to construct and execute the `az rest` command.45## 1. Monthly Cost by Service67```json8{9"type": "ActualCost",10"timeframe": "MonthToDate",11"dataset": {12"granularity": "None",13"aggregation": {14"totalCost": { "name": "Cost", "function": "Sum" }15},16"grouping": [17{ "type": "Dimension", "name": "ServiceName" }18],19"sorting": [20{ "direction": "Descending", "name": "Cost" }21]22}23}24```2526---2728## 2. Daily Cost Trend (Last 30 Days)2930```json31{32"type": "ActualCost",33"timeframe": "Custom",34"timePeriod": {35"from": "2024-01-01T00:00:00Z",36"to": "2024-01-31T23:59:59Z"37},38"dataset": {39"granularity": "Daily",40"aggregation": {41"totalCost": { "name": "Cost", "function": "Sum" }42}43}44}45```4647> ⚠️ **Warning:** Daily granularity supports a maximum of 31 days.4849---5051## 3. Cost by Resource Group with Tag Filter5253```json54{55"type": "ActualCost",56"timeframe": "MonthToDate",57"dataset": {58"granularity": "None",59"aggregation": {60"totalCost": { "name": "Cost", "function": "Sum" }61},62"grouping": [63{ "type": "Dimension", "name": "ResourceGroupName" }64],65"filter": {66"tags": {67"name": "Environment",68"operator": "In",69"values": ["production", "staging"]70}71},72"sorting": [73{ "direction": "Descending", "name": "Cost" }74]75}76}77```7879---8081## 4. Amortized Cost for Reservation Analysis8283```json84{85"type": "AmortizedCost",86"timeframe": "TheLastMonth",87"dataset": {88"granularity": "None",89"aggregation": {90"totalCost": { "name": "Cost", "function": "Sum" }91},92"grouping": [93{ "type": "Dimension", "name": "BenefitName" }94],95"sorting": [96{ "direction": "Descending", "name": "Cost" }97]98}99}100```101102> 💡 **Tip:** `AmortizedCost` spreads reservation purchases across the term for accurate daily/monthly effective cost.103104---105106## 5. Top 10 Most Expensive Resources107108```json109{110"type": "ActualCost",111"timeframe": "MonthToDate",112"dataset": {113"granularity": "None",114"aggregation": {115"totalCost": { "name": "Cost", "function": "Sum" }116},117"grouping": [118{ "type": "Dimension", "name": "ResourceId" }119],120"sorting": [121{ "direction": "Descending", "name": "Cost" }122]123}124}125```126127> 💡 **Tip:** Append `&$top=10` to the URL to limit results: `...query?api-version=2023-11-01&$top=10`128