cloud_billing_report_cost_by_label_dashboard_label_key_inputcloud_billing_report_cost_by_label_dashboard_label_value_costscloud_billing_report_cost_by_label_dashboard_monthly_costcloud_billing_report_cost_by_label_dashboard_projects_inputcloud_billing_report_cost_by_label_dashboard_top_10_label_valuescloud_billing_report_cost_by_label_dashboard_total_costcloud_billing_report_cost_by_label_dashboard_total_projectscloud_billing_report_cost_by_location_dashboard_location_costscloud_billing_report_cost_by_location_dashboard_monthly_costcloud_billing_report_cost_by_location_dashboard_projects_inputcloud_billing_report_cost_by_location_dashboard_top_10_locationscloud_billing_report_cost_by_location_dashboard_total_costcloud_billing_report_cost_by_location_dashboard_total_locationscloud_billing_report_cost_by_location_dashboard_total_projectscloud_billing_report_cost_by_location_dashboard_total_zonescloud_billing_report_cost_by_project_dashboard_monthly_costcloud_billing_report_cost_by_project_dashboard_project_costscloud_billing_report_cost_by_project_dashboard_projects_inputcloud_billing_report_cost_by_project_dashboard_total_costcloud_billing_report_cost_by_project_dashboard_total_projectscloud_billing_report_cost_by_service_dashboard_monthly_costcloud_billing_report_cost_by_service_dashboard_projects_inputcloud_billing_report_cost_by_service_dashboard_service_costscloud_billing_report_cost_by_service_dashboard_top_10_servicescloud_billing_report_cost_by_service_dashboard_total_costcloud_billing_report_cost_by_service_dashboard_total_projectscloud_billing_report_cost_by_service_dashboard_total_servicescloud_billing_report_overview_dashboard_daily_costcloud_billing_report_overview_dashboard_monthly_costcloud_billing_report_overview_dashboard_projects_inputcloud_billing_report_overview_dashboard_top_10_locationscloud_billing_report_overview_dashboard_top_10_projectscloud_billing_report_overview_dashboard_top_10_servicescloud_billing_report_overview_dashboard_total_costcloud_billing_report_overview_dashboard_total_projectscloud_billing_report_overview_dashboard_total_services
Query: cloud_billing_report_cost_by_label_dashboard_monthly_cost
Usage
powerpipe query gcp_cloud_billing_insights.query.cloud_billing_report_cost_by_label_dashboard_monthly_cost
SQL
with filtered as ( select date_trunc('month', usage_start_time) as month, cost, project_labels, labels, system_labels, project_id from gcp_billing_report where ('all' in ($1) or project_id in $1)),picked as ( select f.month, f.cost, json_extract_string(f.project_labels, '$[' || i || '].value') as label_value from filtered f, generate_series(0, 200) as gs(i) where $2 = 'project_labels' and f.project_labels is not null and i < json_array_length(f.project_labels) and json_extract_string(f.project_labels, '$[' || i || '].key') = $3
union all
select f.month, f.cost, json_extract_string(f.labels, '$[' || i || '].value') from filtered f, generate_series(0, 200) as gs(i) where $2 = 'labels' and f.labels is not null and i < json_array_length(f.labels) and json_extract_string(f.labels, '$[' || i || '].key') = $3
union all
select f.month, f.cost, json_extract_string(f.system_labels, '$[' || i || '].value') from filtered f, generate_series(0, 200) as gs(i) where $2 = 'system_labels' and f.system_labels is not null and i < json_array_length(f.system_labels) and json_extract_string(f.system_labels, '$[' || i || '].key') = $3)select strftime(month, '%b %Y') as "Month", label_value as "Series", round(sum(cost), 2) as "Total Cost"from pickedwhere label_value is not null and label_value <> ''group by month, label_valuehaving sum(cost) > 0order by month, sum(cost) desc;
Params
Args | Name | Default | Description | Variable |
---|---|---|---|---|
$1 | project_ids | |||
$2 | label_type | |||
$3 | label_key |
Dashboards
The query is used in the dashboards: