Issue with Cost Managment cli command

Admin (KK) 136 Reputation points
2022-02-16T21:30:28.727+00:00

Hello, I am trying to run an az cli command to get the total cost of all the resources which has tag and when i run the below script i am getting the following error. can someone help me in fix this.

$billingScope = "subscriptions/xxxx"
az costmanagement query --type "Usage" --dataset-aggregation '{\"totalCost\":{\"name\":\"PreTaxCost\",\"function\":\"Sum\"}}'
--dataset-grouping name="ResourceId" type="Dimension" --timeframe "MonthToDate" --scope "$billingScope" `
--dataset-filter '{\"tag\":{\"name\":\"Environment\",\"operator\":\"In\",\"values\":[\"UAT\",\"Prod\"]}}'

Error Message :
az : ERROR: (BadRequest) Invalid query definition: Invalid dataset filter; on a QueryFilter one and only one of and/or/not/dimension/tag can be set.
At line:2 char:1

  • az costmanagement query --type "Usage"`
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (ERROR: (BadRequ...tag can be set.:String) [], RemoteException
  • FullyQualifiedErrorId : NativeCommandError

(Request ID: ff49a644-1bf6-4806-b28c-e8232fd40a80)
Code: BadRequest
Message: Invalid query definition: Invalid dataset filter; on a QueryFilter one and only one of and/or/not/dimension/tag can be set.
(Request ID: ff49a644-1bf6-4806-b28c-e8232fd40a80)

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

1 answer

Sort by: Most helpful
  1. SadiqhAhmed-MSFT 45,271 Reputation points Microsoft Employee
    2022-03-14T06:08:57.317+00:00

    @Admin (KK) You would need to use Usage Details, pull the data to your side and filter the data to what you need.

    0 comments No comments

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.