This project and blog were completed in collaboration with my fellow DSNY14 cohort member, Hewad Shalamkhel.
Introduction
This week's Friday project at the Data School was slightly different from our previous projects. Rather than being asked to build a dashboard or directly answer a business question, we were tasked with building the underlying data model that would enable others to answer that question.
Tanvi and I were assigned to work with Chin & Beards Suds Co. (CBSC), a company selling soaps in various formats, sizes and fragrances.
Our client's business question was:
We'd like to track the specific marketing campaigns for our Coconut fragrance products across the different platforms to see how our engagement and followers gained are doing.
The previous data team had left without sufficient documentation. We were provided with a Snowflake database containing 17 tables, no existing entity relationship diagram (ERD), and data quality issues that needed investigation.
Our challenge was therefore to understand the existing data, establish meaningful relationships between tables and design a reliable and reusable data model.
1. Gathering Business Requirements
Before beginning the technical work, we broke down the client's business question into its individual components.
What constitutes engagement? Which products and platforms are relevant? At what level should we measure marketing performance? How can we associate marketing campaigns with Coconut products?
We also considered whether a higher volume of engagement necessarily represents a larger engaged audience. A thousand interactions generated by ten individuals could tell a very different story from a thousand interactions generated by a thousand individuals. During our requirements-gathering session with Robbin, we clarified several important aspects of the project.
The primary deliverable was an analysis-ready data model stored in Snowflake as a table or view. The model needed to enable future analysts to connect their preferred analytical tools and begin building visualizations without repeating our data preparation work. We also clarified that demonstrating the model through Tableau was a stretch goal rather than a core requirement.
This distinction helped us prioritize the reliability and usability of the underlying data model over the production of a dashboard.
2. SUN and BEAM Modelling
To translate the business requirements into data requirements, we began by creating a SUN model using the seven Ws: Who, What, When, Where, Why, How and How Many.
At the center of our SUN model were the primary measures that the client wanted to track:
- Followers gained
- Total engagement
- Likes
- Shares
- Comments
We then identified the perspectives through which these measures could be analyzed, including marketing platforms, product categories, product sizes, fragrances and dates.
The SUN model helped us narrow our focus from the 17 available tables to those containing information relevant to the business question.

The next step was to use Business Event Analysis and Modelling (BEAM) to define the business event and establish the appropriate level of detail for our marketing data model.
Our intended marketing grain was one row per marketing post, identified by POST_ID.
3. Exploring the Source Data
With no existing ERD or comprehensive documentation, our first technical task was to understand the structure and contents of the available tables.
We used SQL in Snowflake to identify and investigate five potentially relevant tables:
- MARKETING
- MARKETING_FACT_TABLE
- PROMOTIONS
- RECURRING_PROMOTIONS
- PRODUCT_DIMENSION

We approached data exploration from complementary perspectives. While investigating table structures, key uniqueness and cardinality, we also explored individual campaigns, Coconut products, recurring promotions and date discrepancies.
To identify the products relevant to our business question, we initially used:
-- 3.1 Identify Coconut products.
SELECT *
FROM PRODUCT_DIMENSION
WHERE fragrance = 'Coconut';
During our preliminary exploration, we also used a known range of Coconut product IDs and selected Marketing Campaign 48 as an example to investigate how the tables connected. These hardcoded values helped us explore specific records, but they were not intended to become permanent filters in the final data model.
-- 3.2 Investigate a sample marketing campaign and its promotions.
SELECT
TO_DATE(date_time, 'DD/MM/YYYY') AS post_date,
*
FROM MARKETING
WHERE marketing_campaign_id = 48
4. Understanding Grain and Cardinality
Before joining any tables, we needed to understand two fundamental concepts in data modelling: grain and cardinality.
Grain describes what a single row in a table represents.
Cardinality describes how many records in one table can be associated with records in another.
To investigate cardinality, we used three SQL calculations:
-- 4.1 Marketing: investigate post-level grain.
SELECT
COUNT(*) AS total_rows,
COUNT(post_id) AS non_null_ids,
COUNT(DISTINCT post_id) AS unique_ids
FROM MARKETING;
COUNT(*) counts all records, COUNT(product_id) counts non-null product IDs, and COUNT(DISTINCT product_id) counts different product IDs.
By comparing these results across tables, we could establish whether the joining fields contained unique or repeated values.
Promotions and Product Dimension
| Metric | Promotions | Product Dimension |
|---|---|---|
| Total records | 502 | 330 |
| Non-null product IDs | 502 | 330 |
| Distinct product IDs | 235 | 330 |
The Product Dimension table contained 330 records and 330 distinct product IDs, whereas the Promotions table contained 502 records and 235 distinct product IDs.
This demonstrated a many-to-one uniqueness pattern from Promotions to Product Dimension. In business terms, a product can be promoted multiple times, while each promotion record can reference at most one matching product.
Marketing and Promotions
We applied the same logic to the MARKETING_CAMPAIGN_ID field.
| Metric | Marketing | Promotions |
|---|---|---|
| Total records | 8,592 | 502 |
| Non-null campaign IDs | 8,592 | 322 |
| Distinct campaign IDs | 100 | 91 |
Both tables contained repeated marketing campaign IDs, indicating a potential many-to-many relationship. This presented an important modelling challenge. Directly joining marketing posts to promotion records could result in duplicated marketing records and inflated engagement and follower metrics. For example, if a campaign contained ten marketing posts and three promotion records, joining them using the campaign ID would produce thirty records.
Without accounting for this change in grain, an analyst could incorrectly report three times the actual engagement.
5. Designing the Entity Relationship Diagram
After exploring the source tables, we created an ERD to visualize the relationships between marketing posts, promotions, recurring promotions and products. Our proposed model introduced an intermediate Marketing Campaign Bridge table containing distinct campaign IDs associated with Coconut products.
The purpose of this table was to identify relevant campaigns without directly joining marketing posts to multiple promotion records. This design was intended to preserve the post-level grain of the Marketing table while enabling analysts to identify campaigns associated with Coconut products.
Maintaining one row per campaign in the bridge and avoiding unnecessary physical joins between the two many-side tables were important considerations in preventing duplicated marketing measures.

6. Data Cleaning and Transformation
Our exploration revealed several discrepancies that needed to be addressed before constructing the final data model.
Resolving Date and Year Discrepancies
We discovered that the existing YEAR column in the Marketing table did not consistently correspond to the year contained in DATE_TIME. Following our discussion with Robbin, we decided to derive the reporting year directly from DATE_TIME rather than rely on the existing YEAR column.
The following illustrates this transformation:
-- 6.1 Inspect the reporting year derived from the source post date.
SELECT
TO_DATE(date_time, 'DD/MM/YYYY') AS post_date,
YEAR(TO_DATE(date_time, 'DD/MM/YYYY')) AS reporting_year
FROM MARKETING;
This provides a consistent basis for time-based analysis.
Handling Discontinued Products
Another challenge involved identifying discontinued Coconut products.
Because the dataset contained synthetic dates extending into the 2100s, using the actual current date as the reference point would not accurately reflect the reporting period. Following Robbin's recommendation, we decided to use the latest sales transaction date as the reference point for determining the relevant discontinued-product timeframe.
This approach aligns our filtering logic with the timeframe of the dataset rather than the real-world calendar. We used December 31, 2109, as our cutoff for filtering discontinued products and marketing posts.
7. Building the Data Model in Snowflake
Although we initially explored five tables, we ultimately needed only three: MARKETING, PROMOTIONS and PRODUCT_DIMENSION.
We created two new tables:
| Table | Grain |
|---|---|
| DSNY14_MARKETING_BRIDGE_TH | One row per marketing campaign |
| DSNY14_MARKETING_JOINED_TH | One row per marketing post |
Creating the Bridge Table
We joined Promotions with Product Dimension using PRODUCT_ID, filtered for eligible Coconut products and grouped the results by MARKETING_CAMPAIGN_ID.
We also used BOOLOR_AGG to identify whether a campaign was associated with at least one qualifying recurring promotion. This gave us a unique list of relevant campaigns without duplicating marketing records.
Creating the Final Table
We used an INNER JOIN to connect the Marketing table to our bridge table, retaining only posts associated with the relevant campaigns.
-- 7.1 Create destination tables if they do not already exist.
CREATE TABLE IF NOT EXISTS DSNY14_MARKETING_BRIDGE_TH (
MARKETING_CAMPAIGN_ID VARCHAR(16777216) PRIMARY KEY,
IS_RECURRING_PROMOTION BOOLEAN NOT NULL
);
We also added TRUNCATE TABLE before each INSERT statement. Without this step, a future analyst rerunning our script could unintentionally duplicate records.
This introduced us to the concept of idempotency: successfully running the same script multiple times should produce the same result, assuming the source data remains unchanged.
8. Validating the Data Model
Having spent considerable time investigating cardinality, we wanted to ensure that our final table preserved its intended grain.
We returned to the same three SQL calculations used during our initial exploration. All three calculations returned 95, confirming that our final dataset contained 95 unique marketing posts with no missing or repeated post IDs.

9. Client Handover
The final dataset can be accessed directly in Snowflake:
SELECT *
FROM CBSC.CHIN_AND_BEARDS.DSNY14_MARKETING_JOINED_TH;
Analysts can also connect Tableau or another analytical tool directly to this table without creating additional relationships.
When refreshing the model, the bridge table must be populated before the final marketing table. Analysts should also review the hardcoded reporting cutoff when working with a different reporting period.
It is worth noting that our model captures the performance of campaigns associated with Coconut products, rather than performance exclusively attributable to individual Coconut products.

