usage_details.list does not seem to filter by date
- Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
- Package Version:
- Operating System: mac os
- Python Version: 3.7.6
Describe the bug I wrote a script to get usage_details and filter by date.
def get_consumption(credentials, subscription_id, env): consumption_client = ConsumptionManagementClient(credentials,subscription_id,base_url=None)
scope = "\/subscriptions\/" + subscription_id + "\/"
print(scope)
date_filter ='usageStart gt '+ str('2020-02-03T00:00:00Z')
print(date_filter)
for item in consumption_client.usage_details.list(scope, filter=date_filter):
#print("\tProduct: {}".format(item.product))
print(item.date_property,",", item.meter_id, ",", item.name, ",", item.product,",", item.quantity, ",", item.effective_price, ",", item.cost,",", item.unit_price)
#print (item)
To Reproduce Steps to reproduce the behavior:
- See code snipped
Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead I get everything for the February billing period.
Screenshots
If applicable, add screenshots to help explain your problem.

Additional context You can see in the screenshot of results, I am getting items back before the start date of 2020-02-03.
Anyone looking into this?
@nancybelser thanks for following up, @nickzhums can you take a look at this
@RodgeFu seems like the API behavior is not what the user expected, could you have someone take a look and double check. Thanks!
The response is from consumption service, and we need consumption team's help
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc
Any updates on this issue?
Hi @nancybelser thanks so much for the feedback and the patience. I'm working to route this issue to someone on the Consumption team. I apologize for the delay.
@ms-premp please loop in the right people to take a look at the issue. Thanks!
Any updates on this?
@addesai please have a look... it looks like the filter is not passed in correctly.
If the filter logic I am using is incorrect, can someone give me the correct syntax, please? Thanks.
What I am gathering is the test case example I found in this repo is not a valid option for usage_details. def test_consumption_subscription_usage_filter(self): date_filter ='usageEnd le '+ str(MgmtConsumptionTest.endDate) pages = self.consumption_client.usage_details.list(expand='meterDetails', filter=date_filter, top=10) first_page = pages.advance_page() output = list(first_page) self.assertEqual(10, len(output)) self._validate_usage(output[0], include_meter_details=True)
Here is where I found the logic: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py .
@nancybelser apologies for bad examples. we will work on fixing those. Meanwhile, please use following as example on how to pass in date filters for calling consumption.
https://github.com/ms-premp/AzureConsumptionSamples/blob/master/Python_sdk/usage_details_list_python_sdk_example.py
Please note that API expects both start and end dates to be able to filter data as mentioned in following doc https://docs.microsoft.com/en-us/rest/api/consumption/#working-with-billing-periods-and-date-ranges
Hope this helps.