Skip to content

[Feature]: Invoke-AzCostManagementQuery improve output #27735

Open
@o-l-a-v

Description

@o-l-a-v

Description of the new feature

The output of Invoke-AzCostManagementQuery is not intuitive to work with. Example:

$null = Add-Member -InputObject $Subscription -Force -NotePropertyName 'ConsumptionTwoWeeksAgo' -NotePropertyValue (
    Invoke-AzCostManagementQuery -WhatIf:$false -DatasetAggregation @{
        'totalCost' = @{
            'name'     = [string] 'Cost'
            'function' = [string] 'SUM'
        }
    } -Type 'ActualCost' -Timeframe 'Custom' `
        -Scope ('/subscriptions/{0}' -f $Subscription.'Id') `
        -TimePeriodFrom $StartOfTwoWeeksAgo.ToString('o') `
        -TimePeriodTo  $EndOfTwoWeeksAgo.ToString('o') 6>$null
)

Results to JSON:

{
  "Column": [
    {
      "Name": "Cost",
      "Type": "Number"
    },
    {
      "Name": "Currency",
      "Type": "String"
    }
  ],
  "ETag": null,
  "Id": null,
  "Location": null,
  "Name": null,
  "NextLink": null,
  "ResourceGroupName": null,
  "Row": [
    [
      "9,126E-05",
      "DKK"
    ]
  ],
  "Sku": null,
  "Tag": {},
  "Type": null,
  "Property": {
    "Column": [
      {
        "Name": "Cost",
        "Type": "Number"
      },
      {
        "Name": "Currency",
        "Type": "String"
      }
    ],
    "NextLink": null,
    "Row": [
      [
        "9,126E-05",
        "DKK"
      ]
    ]
  }
}

To get the sum and currency one have to do something like this:

$null = Add-Member -InputObject $Subscription -Force -NotePropertyMembers @{
    'Currency'       = [string]$(Try{$Subscription.'ConsumptionLastWeek'.'Row'[0][1]}Catch{''})
    'SumLastWeek'    = [double]::Parse($(Try{$Subscription.'ConsumptionLastWeek'.'Row'[0][0]}Catch{0}))
    'SumTwoWeeksAgo' = [double]::Parse($(Try{$Subscription.'ConsumptionTwoWeeksAgo'.'Row'[0][0]}Catch{0}))
}

Proposed implementation details (optional)

Make sum and currency into properties, instead of having to index rows as an array.

Activity

added
feature-requestThis issue requires a new behavior in the product in order be resolved.
needs-triageThis is a new issue that needs to be triaged to the appropriate team.
on May 12, 2025
added
needs-triageThis is a new issue that needs to be triaged to the appropriate team.
and removed
needs-triageThis is a new issue that needs to be triaged to the appropriate team.
on May 12, 2025
added
Service AttentionThis issue is responsible by Azure service team.
Cost Management - QueryAll issues in cost management and Consumption for query API associated to tags, dimensions and forec
and removed
needs-triageThis is a new issue that needs to be triaged to the appropriate team.
on May 16, 2025
microsoft-github-policy-service

microsoft-github-policy-service commented on May 16, 2025

@microsoft-github-policy-service
Contributor

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ccmixpdevs.

microsoft-github-policy-service

microsoft-github-policy-service commented on May 16, 2025

@microsoft-github-policy-service
Contributor

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ccmixpdevs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Cost Management - QueryAll issues in cost management and Consumption for query API associated to tags, dimensions and forecService AttentionThis issue is responsible by Azure service team.customer-reportedfeature-requestThis issue requires a new behavior in the product in order be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @o-l-a-v@isra-fel

        Issue actions

          [Feature]: `Invoke-AzCostManagementQuery` improve output · Issue #27735 · Azure/azure-powershell