or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

aggregated-cost.mdbudget-management.mdclient-management.mdcost-analysis.mdcredits-billing.mdindex.mdoperations.mdreservation-management.mdtags-operations.mdusage-analytics.md

aggregated-cost.mddocs/

0

# Aggregated Cost Analysis

1

2

Access aggregated cost data for management groups across current and historical billing periods for comprehensive cost oversight and management group cost analysis.

3

4

## Capabilities

5

6

### Current Period Aggregated Costs

7

8

Get the aggregate cost of a management group and all child management groups for the current billing period.

9

10

```python { .api }

11

def get_by_management_group(

12

management_group_id: str,

13

filter: str = None,

14

**kwargs

15

) -> ManagementGroupAggregatedCostResult:

16

"""

17

Provides the aggregate cost of a management group and all child management groups by current billing period.

18

19

Parameters:

20

- management_group_id: Azure Management Group ID (str)

21

- filter: May be used to filter aggregated cost by properties/usageDate (Utc time),

22

properties/chargeType or properties/publisherType. Supported operators are 'eq', 'lt', 'gt', 'le', 'ge' (str, optional)

23

24

Returns:

25

ManagementGroupAggregatedCostResult: Aggregated cost data with usage dates, costs, and charge types

26

"""

27

```

28

29

### Historical Period Aggregated Costs

30

31

Get the aggregate cost of a management group and all child management groups for a specific historical billing period.

32

33

```python { .api }

34

def get_for_billing_period_by_management_group(

35

management_group_id: str,

36

billing_period_name: str,

37

**kwargs

38

) -> ManagementGroupAggregatedCostResult:

39

"""

40

Provides the aggregate cost of a management group and all child management groups by specified billing period.

41

42

Parameters:

43

- management_group_id: Azure Management Group ID (str)

44

- billing_period_name: Billing Period Name (str)

45

46

Returns:

47

ManagementGroupAggregatedCostResult: Historical aggregated cost data for the specified billing period

48

"""

49

```

50

51

## Usage Examples

52

53

```python

54

from azure.identity import DefaultAzureCredential

55

from azure.mgmt.consumption import ConsumptionManagementClient

56

57

# Authenticate and create client

58

credential = DefaultAzureCredential()

59

subscription_id = "your-subscription-id"

60

client = ConsumptionManagementClient(credential, subscription_id)

61

62

# Get current billing period aggregated costs for a management group

63

management_group_id = "your-management-group-id"

64

current_costs = client.aggregated_cost.get_by_management_group(

65

management_group_id=management_group_id

66

)

67

68

print(f"Current period aggregated cost: {current_costs.properties.billing_period_id}")

69

print(f"Total cost: {current_costs.properties.charge_summary.value} {current_costs.properties.currency}")

70

71

# Get aggregated costs with date filter

72

from datetime import datetime, timedelta

73

end_date = datetime.now()

74

start_date = end_date - timedelta(days=30)

75

76

date_filter = f"properties/usageDate ge '{start_date.strftime('%Y-%m-%d')}' and properties/usageDate le '{end_date.strftime('%Y-%m-%d')}'"

77

filtered_costs = client.aggregated_cost.get_by_management_group(

78

management_group_id=management_group_id,

79

filter=date_filter

80

)

81

82

# Get historical billing period costs

83

billing_period = "202401" # January 2024

84

historical_costs = client.aggregated_cost.get_for_billing_period_by_management_group(

85

management_group_id=management_group_id,

86

billing_period_name=billing_period

87

)

88

89

print(f"Historical period {billing_period} cost: {historical_costs.properties.charge_summary.value}")

90

```

91

92

## Types

93

94

```python { .api }

95

class ManagementGroupAggregatedCostResult:

96

id: str

97

name: str

98

type: str

99

etag: str

100

properties: ManagementGroupAggregatedCostProperties

101

102

class ManagementGroupAggregatedCostProperties:

103

billing_period_id: str

104

usage_start: datetime

105

usage_end: datetime

106

azure_charges: float

107

marketplace_charges: float

108

charge_summary: ChargeSummary

109

children: List[ManagementGroupAggregatedCostResult]

110

included_subscriptions: List[str]

111

excluded_subscriptions: List[str]

112

currency: str

113

114

class ChargeSummary:

115

value: float

116

currency: str

117

```