Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @IM_01,

Here is a simple example..

%sql
CREATE SCHEMA IF NOT EXISTS uc_customer_demo_catalog.metric_demo;

CREATE OR REPLACE TABLE uc_customer_demo_catalog.metric_demo.orders (
  order_id   INT,
  order_date DATE,
  country    STRING,
  product    STRING,
  revenue    DOUBLE
);

INSERT INTO uc_customer_demo_catalog.metric_demo.orders VALUES
  (1, '2025-01-01', 'US', 'Laptop', 1200.0),
  (2, '2025-01-02', 'US', 'Laptop',  800.0),
  (3, '2025-01-03', 'US', 'Phone',   500.0),
  (4, '2025-01-01', 'UK', 'Laptop', 1000.0),
  (5, '2025-01-02', 'UK', 'Phone',   400.0),
  (6, '2025-01-03', 'UK', 'Phone',   600.0),
  (7, '2025-01-04', 'DE', 'Laptop',  700.0),
  (8, '2025-01-04', 'DE', 'Phone',   300.0);

Created a metric view as below.

metric_view.png

 And here is the query I used.. 

SELECT
  country,
  product,
  MEASURE(total_revenue) AS total_revenue
FROM uc_customer_demo_catalog.metric_demo.orders_metric_view
GROUP BY GROUPING SETS (
  (country, product),
  (country),
  (product),
  ()
)
ORDER BY country, product;

Ashwin_DSA_0-1776098623292.png

Does this give you an idea?

If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.

 

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***