Conditional grouping of costs using Azure Cost Management Query API

Onur Micoogullari 31 Reputation points


I have a client that needs to be able to generate a billing report from Azure where costs from Resources in multiple Subscriptions under the same Department are grouped by a certain Tag and its Value. I know that this can be done using the Azure Cost Management Query API, but my client has a certain requirements regarding 'conditional grouping'.

The requirement is as follows: If Tag A has a value of N/A, group on tag B. Otherwise - group on Tag A.

Is this possible using Azure Cost Management Query API? I guess we could create a seperate tag, Tag C, which could combine the values of Tag A and Tag B, and group on Tag C. But it seems like a kind of ugly solution to the problem. Also, this is not scalable in the sense that changing grouping conditions for the report would mean that we would have to change the value of Tag C on all resources.

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,215 questions
0 comments No comments
{count} vote

Accepted answer
  1. Carlos Villagomez 1,106 Reputation points Microsoft Employee

    Hello @Onur Micoogullari ,

    Thank you for your post! I did some research and investigation with our Azure Cost Management team, we discovered that it's acutally not possible to implement Conditional grouping of costs using the Query API. Instead, you would need to use raw cost details in order to apply conditional grouping per the followign document here.

    Please let me know if you have any further questions or concerns regarding this process and we'll be happy to assist you further and I hope this gets you on the right path towards implementing the solution!

    Carlos V.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Onur Micoogullari 31 Reputation points

    Thank you Carlos for responding so fast and clarifying the limitations around conditional grouping using Azure Cost Management Query API.

    Based on your answer, I will be able to further investigate to find the best solution for my client.

    1 person found this answer helpful.