Azure Cost Management API - not getting the same results in Azure Workbooks

Anonymous
2023-10-10T09:29:03.1133333+00:00

I am using the Azure Cost Management API : '/subscriptions/{Subscription:subscriptionid}/providers/Microsoft.CostManagement/query?' to get daily Databricks jobs costs using jobid argument in my request in Azure Workbook. ( {Subscription:subscriptionid} is a parameter set in the workbook).

I have an 'Application' dropdown parameter that represents jobid values for each application, represented by a json:

[
	{  	
	"value": [jobid1, jobid2, jobid3], "label":"App1" 
}, 
	{   
	"value": [jobid1, jobid2, jobid3] , "label": "App2" 
}
]

This is the body of my request :

{
   "type": "Usage",
   "timeframe": "MonthToDate",
   "dataset": {
     "granularity": "Daily",
     "filter": {
                 "tags" : {
                     "name" : "jobid",
                     "operator" : "In",
                     "values" : {Application:escapejson}
                 }
     },
     "aggregation": { "totalCost": {"name": "Cost","function": "Sum"}},
     "grouping": [
       {
         "type": "TagKey",
         "name": "jobid"
       }
     ]
   }

The problem is that i am not getting the same results as the ones in Azure Cost Management Analysis service, where I filter by the same jobids for each view (app).

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

1 answer

Sort by: Most helpful
  1. Monalla-MSFT 13,071 Reputation points Moderator
    2023-10-11T19:31:55.1+00:00

    @Anonymous - Welcome to Microsoft Q&A and thanks for reaching out to us.

    Most likely the JobId values should be in string format to get the same results as the ones in Azure cost Management Analysis service.

    Please modify your JSON to have the JobId values in a string format as below.

    [
    	{  	
    	"value": "jobid1,jobid2,jobid3", "label":"App1" 
    }, 
    	{   
    	"value": "jobid1,jobid2,jobid3" , "label": "App2" 
    }
    ]
    
    

    Once you have modified your JSON, you can update your request body to use the correct jobid values as below:

    {
       "type": "Usage",
       "timeframe": "MonthToDate",
       "dataset": {
         "granularity": "Daily",
         "filter": {
                     "tags" : {
                         "name" : "jobid",
                         "operator" : "In",
                         "values" : "{Application:escapejson}"
                     }
         },
         "aggregation": { "totalCost": {"name": "Cost","function": "Sum"}},
         "grouping": [
           {
             "type": "TagKey",
             "name": "jobid"
           }
         ]
       }
    }
    

    Make sure to replace the {Application:escapejson} parameter with the correct jobid values in a string format.

    If you are still not getting the expected results, you can try to debug your request by checking the API response and comparing it with the results in Azure Cost Management Analysis service. You can also try to modify your request by changing the timeframe or the grouping options to see if it affects the results.

    Hope this helps. and please feel free to reach out if you have any further questions.


    If the above response was helpful, please feel free to "Accept as Answer" and click "Yes" so it can be beneficial to the community.

    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.