Showing posts with label 194 ) Grain and granularity. Show all posts
Showing posts with label 194 ) Grain and granularity. Show all posts

Wednesday, August 12, 2026

194 ) Grain and granularity


Grain and granularity 


  • Grain is stated using minimum column names combination   that uniquely define a single row , not a numeric count of columns.

  • Granularity 

  •  Granularity in data refers to the level of detail 
  • is expressed in levels of detail or hierarchy (e.g., transactional level, daily level, monthly level, or region level) describing how coarse or fine the data is.

  

The client wants to know how many policies are sold per month in a region."

Step 1: Break down the request

  • Metric: Number of policies sold (Count of Policy ID).
  • Dimensions: Time (Month) and Geography (Region).

Step 2: Determine the atomic level (The Grain)

 

Grain = One row per policy sale 

(  Policy_ID, Sale_Date, Agent_ID, Customer_ID, Branch_ID, Region_ID).

Granularity

It is at the transaction level (specifically, one row per individual policy sale).

It would be at the store level (or branch level) if the data was aggregated to track total sales metrics per branch per day (e.g., Branch_ID, Sale_Date, and Total_Sales_Amount), 

215 ) query : Customers Purchasing the Same Product in Different Stores in Same Month

  /*  ### Step 1: DDL & DML (Sample Data Setup) ```sql -- 1. Create Orders Table */ DROP TABLE customerorders ; CREATE TABLE custome...