You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用$filter查询Azure Consumption用量详情返回错误结果求助

Troubleshooting Unexpected Results When Filtering Consumption API by consumedService

Let’s break down why you’re seeing non-Microsoft.DBforPostgreSQL entries in your response (even though your date filter works correctly) and how to fix it to get accurate PostgreSQL/MySQL usage data.

Possible Causes & Fixes

1. Outdated API Version Limitation

The 2019-01-01 API version you’re using is quite old, and early iterations of the Consumption API had inconsistencies in how the consumedService filter was applied. Some services weren’t correctly categorized, or the filter logic had bugs that let mismatched entries slip through.

Fix: Upgrade to a newer, stable API version (e.g., 2023-11-01 is the latest at the time of writing). Update your request URL to use this version:

GET https://management.azure.com/subscriptions/SUBSCRIPTION/providers/Microsoft.Consumption/usageDetails?api-version=2023-11-01&$filter=properties%2FconsumedService%20eq%20%27Microsoft.DBforPostgreSQL%27%20and%20properties%2FusageStart%20ge%20%272019-08-07T00%3A00%3A00Z%27%20and%20properties%2FusageEnd%20lt%20%272019-08-09T01%3A00%3A00Z%27

Newer versions have refined filtering accuracy and service categorization, which should resolve the mismatched entries.

2. Associated Resource Usage

Some entries you’re seeing (like Microsoft.Storage or Microsoft.Compute) might actually be tied to your PostgreSQL instances. For example, Azure Database for PostgreSQL uses underlying storage and compute resources that are billed under their respective service names but linked to your PostgreSQL deployment.

Check: Look at the resourceId or resourceGroup fields in the unexpected entries. If they point to your PostgreSQL instances, these are legitimate associated costs. If you want to exclude them, you can add an additional filter to target specific resourceType values — just note this will remove related costs that are part of your PostgreSQL deployment.

3. Filter Logic for Multiple Target Services

Since you need both PostgreSQL and MySQL data, update your filter to include both services explicitly (using or):

$filter=(properties/consumedService eq 'Microsoft.DBforPostgreSQL' or properties/consumedService eq 'Microsoft.DBforMySQL') and properties/usageStart ge '2019-08-07T00:00:00Z' and properties/usageEnd lt '2019-08-09T01:00:00Z'

Don’t forget to apply proper URL encoding for this extended filter when constructing your request.

Additional Tips

  • Use the $select parameter to narrow down the response to only the fields you need (e.g., $select=properties/consumedService,properties/usageStart,properties/usageEnd,properties/cost) — this makes verifying filter results much faster.
  • If you still see unexpected entries after upgrading the API version, cross-check your Azure Cost Management portal manually to confirm if those are legitimate cross-service charges or a reporting anomaly.

内容的提问来源于stack exchange,提问作者Roman Alekseiev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:43:43