<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lanang Bagaskara on Medium]]></title>
        <description><![CDATA[Stories by Lanang Bagaskara on Medium]]></description>
        <link>https://medium.com/@lanang.bagaskaraa?source=rss-ac7bdba34cff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zIwrGGUu39KiTQrG</url>
            <title>Stories by Lanang Bagaskara on Medium</title>
            <link>https://medium.com/@lanang.bagaskaraa?source=rss-ac7bdba34cff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 23:26:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lanang.bagaskaraa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unlocking Insights: Analyzing Retail Sales Data with SQL]]></title>
            <link>https://medium.com/@lanang.bagaskaraa/unlocking-insights-analyzing-retail-sales-data-with-sql-5da9eb91525f?source=rss-ac7bdba34cff------2</link>
            <guid isPermaLink="false">https://medium.com/p/5da9eb91525f</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[cohort-analysis]]></category>
            <dc:creator><![CDATA[Lanang Bagaskara]]></dc:creator>
            <pubDate>Mon, 30 Sep 2024 07:16:37 GMT</pubDate>
            <atom:updated>2024-11-21T04:56:09.336Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NOv3zv5vdkVsKEfJ" /><figcaption>Photo by <a href="https://unsplash.com/@rupixen?utm_source=medium&amp;utm_medium=referral">rupixen</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The retail industry is known for its competitive ecosystem. Understanding sales trends and customer purchasing behavior is critical for optimizing operations and driving revenue. This analysis explores a retail sales dataset to uncover key insights, including peak sales periods, top-performing products, and customer purchasing patterns. By the end, we’ll have actionable insights to support data-driven decisions, from inventory management to marketing strategies.</p><h4>Dataset Overview</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*KsftLVhfJDNFzkI2mMJigg.png" /><figcaption>Data Scheme of this dataset</figcaption></figure><p>The diagram shows a <strong>relational database schema</strong> representing a retail sales dataset that spans from January 7th, 2021, to December 8th, 2022, and can be accessed <a href="https://github.com/CountingCrows/Retail-Sales-Data-with-SQL/tree/main/dataset">here</a>.</p><p><strong>order_detail: </strong>This table tracks every transaction, including the order ID, customer ID, transaction date, product details (SKU), and the pricing both before and after discounts. It also includes flags for whether the transaction is gross (incomplete), valid (paid), or net (completed). Payment method IDs are also included for each transaction.</p><p><strong>sku_detail: </strong>This table provides product information, such as product names, base prices, cost of goods sold (COGS), and categories, making it easy to categorize and analyze product sales.</p><p><strong>customer_detail: </strong>This table records customer data, including unique customer IDs and registration dates, helping us understand customer demographics and engagement.</p><p><strong>payment_detail: </strong>This table stores payment method data, including the unique ID and its description, allowing us to analyze the popularity and performance of different payment options.</p><p>Our <strong>analysis</strong> will address the following key questions:</p><ol><li>When are peak sales periods?</li><li>What are the most popular products?</li><li>How do different segments behave?</li></ol><h4>Analyzing Total Sales Over Time</h4><pre>SELECT<br> EXTRACT(MONTH FROM order_date) AS month,<br> ROUND(SUM(after_discount)::numeric,2) AS total_transaction<br>FROM order_detail<br>WHERE EXTRACT(YEAR FROM order_date) = 2021<br>AND is_valid = 1<br>GROUP BY month<br>ORDER BY total_transaction DESC;</pre><blockquote>We want to use a query that calculates the total transaction amount after discounts for each month in 2021. It extracts the month from the order_date, sums the after_discount values for valid orders (is_valid = 1), and rounds the total to two decimal places. The results are grouped by month and sorted by the total transaction amount in descending order.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*DZAU12qoZeydAlmVBJyFKg.png" /></figure><p>We can see from the chart that there is a seasonal trend starting from July. But, will it be more interesting to know how many customers made a transaction and the total number of products sold each month? For that, we can use this query;</p><pre>SELECT<br> EXTRACT(MONTH FROM order_date) AS month,<br> COUNT(customer_id) AS total_customers,<br> SUM(qty_ordered) AS total_qty_ordered,<br> ROUND(SUM(after_discount)::numeric,2) AS total_transaction<br>FROM order_detail<br>WHERE EXTRACT(YEAR FROM order_date) = 2021<br>AND is_valid = 1<br>GROUP BY month<br>ORDER BY total_transaction DESC;</pre><blockquote>total_customers: The number of unique customers for each month.</blockquote><blockquote>total_qty_ordered: The total quantity of items ordered each month.</blockquote><blockquote>total_transaction: The total transaction amount after discounts, rounded to two decimal places.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*ySJzVA5-xrJSnO9k6ChuwQ.png" /></figure><p>Having more detailed information on what month has the highest total transaction we can also see how many customers made transactions and the number of transactions that occurred in each month.</p><p><strong>Capitalize on High Sales Periods:</strong></p><ul><li>Offer targeted promotions or discounts leading up to August, October, and December to maximize revenue during these peak periods.</li><li>Consider stocking high-demand products earlier to avoid supply shortages during these months.</li></ul><p><strong>Boost Sales During Low Months:</strong></p><ul><li>Implement marketing campaigns in March and April to encourage purchases, such as discounts or special product bundles.</li><li>Analyze customer feedback or seasonal preferences to understand why sales are lower during these months.</li></ul><p><strong>Enhance Customer Engagement:</strong></p><ul><li>Increase engagement with loyalty programs or special rewards for repeat purchases, especially during high-demand months like August and December.</li><li>Use insights from high-engagement months to replicate successful strategies (e.g., product bundles, festive offers).</li></ul><p><strong>Customer Retention Strategy:</strong></p><ul><li>Develop personalized offers or post-purchase engagement strategies for customers active during peak months to encourage repeat transactions throughout the year.</li></ul><p>Given the dataset originates from Pakistan, the sales peak in August and December is likely influenced by cultural factors, such as holidays and festivals that drive higher customer demand.</p><p>In summary, the data suggests strong sales performance in the second half of the year, with notable peaks in August, October, and December. Customer engagement and order quantities also rise significantly during these periods.</p><h4>Identifying Top-Selling Categories</h4><p>Knowing which categories are top sellers lets us focus on high-demand items and ensure adequate stock levels.</p><pre>SELECT<br> sd.category AS category,<br> COUNT(od.customer_id) AS total_customers,<br> SUM(od.qty_ordered) AS total_quantity_ordered,<br>  ROUND(SUM(od.after_discount)::numeric,2) AS total_transaction<br>FROM order_detail od<br>LEFT JOIN sku_detail sd ON od.sku_id = sd.id<br>WHERE EXTRACT(YEAR FROM od.order_date) = 2022<br>AND od.is_valid = 1<br>GROUP BY sd.category<br>ORDER BY total_quantity_ordered DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*nFX4OE4-C2Ht7suI9pP7tQ.png" /></figure><ul><li>The highest total transactions occurred in Mobiles &amp; Tablets category for 918,451,576, followed by Entertainment for 365,344,148.9.</li><li>The increase of amount in total transactions for the Mobiles &amp; Tablets category and Entertainment points that there’s an increase usage of technology and digitalization, which can also be triggered by the need for devices for online education and online entertainment facilities at home since the COVID-19 pandemic between 2021 till 2022.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*OdljbCOsiURNRXjrGwF4eA.png" /></figure><h4>Analyzing Category Shifts between 2021 and 2022</h4><p>Identifying categories with increased transaction values can reveal areas of growth and opportunities to invest further, while understanding categories with decreased transaction values can help address potential issues, such as changing customer needs, pricing challenges, or seasonal factors.</p><pre>WITH transactions_2021 AS(<br> SELECT<br>  sd.category AS category,<br>  SUM(od.after_discount) AS total_transaction_2021<br> FROM order_detail od<br> LEFT JOIN sku_detail sd ON od.sku_id = sd.id<br> WHERE EXTRACT(YEAR FROM od.order_date) = 2021<br> AND od.is_valid = 1<br> GROUP BY sd.category<br>),<br>transactions_2022 AS(<br> SELECT<br>  sd.category AS category,<br>  SUM(od.after_discount) AS total_transaction_2022<br> FROM order_detail od<br> LEFT JOIN sku_detail sd ON od.sku_id = sd.id<br> WHERE EXTRACT(YEAR FROM od.order_date) = 2022<br> AND od.is_valid = 1<br> GROUP BY sd.category<br>)<br>SELECT<br>    COALESCE(t2021.category, t2022.category) AS category,<br>    COALESCE(t2021.total_transaction_2021, 0) AS total_transaction_2021,<br>    COALESCE(t2022.total_transaction_2022, 0) AS total_transaction_2022,<br>    COALESCE(t2022.total_transaction_2022, 0) - COALESCE(t2021.total_transaction_2021, 0) AS difference,<br>    CASE<br>        WHEN COALESCE(t2022.total_transaction_2022, 0) - COALESCE(t2021.total_transaction_2021, 0) &gt; 0 THEN &#39;Increase&#39;<br>        WHEN COALESCE(t2022.total_transaction_2022, 0) - COALESCE(t2021.total_transaction_2021, 0) &lt; 0 THEN &#39;Decrease&#39;<br>        ELSE &#39;No Change&#39;<br>    END AS change_type<br>FROM transactions_2021 t2021<br>FULL OUTER JOIN transactions_2022 t2022 ON t2021.category = t2022.category<br>ORDER BY difference DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*owF5-0fDdwdJExm4FSJbZA.png" /></figure><ul><li>The Mobiles &amp; Tablets category experienced an increase of the highest total value transactions for 547,844,858. On the other hand, the category Others had a decrease in the total value of transactions for 18,723,869.-</li><li>The increase in the category of Mobiles &amp; Tablets is possibly due to the increase in the need for digital devices to facilitate online education since the COVID-19 pandemic.</li></ul><p>Comparing transaction values reveals that some categories experienced growth, while others, like the “Other” category, saw a significant decline. This drop in the “Other” category stands out and needs further investigation.</p><p><strong>Others</strong></p><p>We’ll be using Inner Join to observe the difference in total products sold from each product between 2021 and 2022 in this categories.</p><pre>WITH transactions_2021 AS(<br> SELECT<br>  sd.sku_name AS product_name,<br>  SUM(od.qty_ordered) AS total_qty_ordered_2021<br> FROM order_detail od<br> LEFT JOIN sku_detail sd ON od.sku_id = sd.id<br> WHERE EXTRACT(YEAR FROM od.order_date) = 2021<br> AND category = &#39;Others&#39;<br> AND od.is_valid = 1<br> GROUP BY sd.sku_name<br>),<br>transactions_2022 AS(<br> SELECT<br>  sd.sku_name AS product_name,<br>  SUM(od.qty_ordered) AS total_qty_ordered_2022<br> FROM order_detail od<br> LEFT JOIN sku_detail sd ON od.sku_id = sd.id<br> WHERE EXTRACT(YEAR FROM od.order_date) = 2022<br> AND category = &#39;Others&#39;<br> AND od.is_valid = 1<br> GROUP BY sd.sku_name<br>)<br>SELECT<br>    COALESCE(t2021.product_name, t2022.product_name) AS product_name,<br>    COALESCE(t2021.total_qty_ordered_2021, 0) AS total_qty_ordered_2021,<br>    COALESCE(t2022.total_qty_ordered_2022, 0) AS total_qty_ordered_2022,<br>    COALESCE(t2022.total_qty_ordered_2022, 0) - COALESCE(t2021.total_qty_ordered_2021, 0) AS difference,<br>    CASE<br>        WHEN COALESCE(t2022.total_qty_ordered_2022, 0) - COALESCE(t2021.total_qty_ordered_2021, 0) &gt; 0 THEN &#39;Increase&#39;<br>        WHEN COALESCE(t2022.total_qty_ordered_2022, 0) - COALESCE(t2021.total_qty_ordered_2021, 0) &lt; 0 THEN &#39;Decrease&#39;<br>        ELSE &#39;No Change&#39;<br>    END AS change_type<br>FROM transactions_2021 t2021<br>INNER JOIN transactions_2022 t2022 ON t2021.product_name = t2022.product_name<br>ORDER BY difference DESC<br>LIMIT 5;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*7orqVaCJSSn_X4k6CxpS1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*exXJ3re2i1zEGM0AgrJaEw.png" /></figure><p>From the query, we notice that the product RB Dettol Germ Busting Kit bf experienced the highest decrease and emart_Tyre Shape Air Compressor has the highest increase of sales.</p><h4>Comparing Brand Performance: Sorting Top 5 Brands by Total Transaction Value</h4><p>Analyzing the total transaction value across major brands provides a clear picture of consumer spending patterns and brand performance. By sorting Samsung, Apple, Sony, Huawei, and Lenovo based on their transaction values, we can identify which brands are leading in terms of sales and customer demand.</p><pre>SELECT<br> CASE<br>  WHEN sd.sku_name LIKE &#39;%Samsung%&#39; THEN &#39;Samsung&#39;<br>  WHEN sd.sku_name LIKE &#39;%Apple%&#39; THEN &#39;Apple&#39;<br>  WHEN sd.sku_name LIKE &#39;%Sony%&#39; THEN &#39;Sony&#39;<br>  WHEN sd.sku_name LIKE &#39;%Huawei%&#39; THEN &#39;Huawei&#39;<br>  WHEN sd.sku_name LIKE &#39;%Lenovo%&#39; THEN &#39;Lenovo&#39;<br>  Else &#39;Other&#39;<br> END AS brand,<br> SUM(od.qty_ordered) AS total_qty_ordered,<br> SUM(od.after_discount) AS total_transaction<br>FROM order_detail od<br>LEFT JOIN sku_detail sd ON od.sku_id = sd.id<br>WHERE od.is_valid = 1<br>AND (<br>    sd.sku_name LIKE &#39;%Samsung%&#39; OR<br>    sd.sku_name LIKE &#39;%Apple%&#39; OR<br>    sd.sku_name LIKE &#39;%Sony%&#39; OR<br>    sd.sku_name LIKE &#39;%Huawei%&#39; OR<br>    sd.sku_name LIKE &#39;%Lenovo%&#39;<br>)<br>GROUP BY brand<br>ORDER BY total_transaction DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*nGsfmfGqJhLbtNVANs9YGA.png" /></figure><blockquote>Adding product names and also the total amount of items sold to see the bigger picture.</blockquote><pre>SELECT<br> sd.sku_name AS product_name,<br> CASE<br>  WHEN sd.sku_name LIKE &#39;%Samsung%&#39; THEN &#39;Samsung&#39;<br>  WHEN sd.sku_name LIKE &#39;%Apple%&#39; THEN &#39;Apple&#39;<br>  WHEN sd.sku_name LIKE &#39;%Sony%&#39; THEN &#39;Sony&#39;<br>  WHEN sd.sku_name LIKE &#39;%Huawei%&#39; THEN &#39;Huawei&#39;<br>  WHEN sd.sku_name LIKE &#39;%Lenovo%&#39; THEN &#39;Lenovo&#39;<br>  Else &#39;Other&#39;<br> END AS brand,<br> SUM(od.qty_ordered) AS total_qty_ordered,<br> SUM(od.after_discount) AS total_transaction<br>FROM order_detail od<br>LEFT JOIN sku_detail sd ON od.sku_id = sd.id<br>WHERE od.is_valid = 1<br>AND (<br>    sd.sku_name LIKE &#39;%Samsung%&#39; OR<br>    sd.sku_name LIKE &#39;%Apple%&#39; OR<br>    sd.sku_name LIKE &#39;%Sony%&#39; OR<br>    sd.sku_name LIKE &#39;%Huawei%&#39; OR<br>    sd.sku_name LIKE &#39;%Lenovo%&#39;<br>)<br>GROUP BY product_name, brand<br>ORDER BY total_transaction DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*3U-08z5u7XoIncssah2KnA.png" /></figure><p>Based on the provided data for different brands, here are some insights:</p><p><strong>Samsung Dominates the Market: </strong>Samsung leads with the highest transaction value and the largest number of products sold. This indicates a strong foothold and high demand in the market.</p><p><strong>Apple’s Premium Pricing Power: </strong>Despite selling fewer units, Apple has the second-highest transaction value, showcasing its dominance in the premium segment with higher-priced products.</p><p>Samsung dominates both in volume and value, while Apple excels in premium, high-value transactions. Huawei and Sony maintain mid-level performance, and Lenovo targets niche, budget-friendly consumers. These insights guide strategies for targeting different market segments effectively.</p><h4>Unpacking Payment Choices</h4><p>Understanding the payment methods preferred by customers is essential for optimizing transaction processes and improving overall customer experience. By analyzing the top 5 payment methods used in 2022, this analysis provides valuable insights into customer behavior and preferences.</p><pre>SELECT<br> pd.payment_method AS payment_method,<br> COUNT(DISTINCT od.id) AS total_unique_order,<br> ROUND(SUM(od.after_discount)::numeric, 2) AS total_transaction<br>FROM order_detail od<br>LEFT JOIN payment_detail pd ON od.payment_id = pd.id<br>WHERE EXTRACT(YEAR FROM od.order_date) = 2022<br>AND od.is_valid = 1<br>GROUP BY payment_method<br>ORDER BY total_unique_order DESC<br>LIMIT 5;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*I8JOgmdPfpLyYliFhExPbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*3PmdzP-pOoRpB2xhJQuPAg.png" /></figure><ul><li>The most used payment method in 2022 is <strong>Cash On Delivery</strong> (<strong>cod</strong>) for 1809 transactions.</li><li>The domination of this payment method shows us the customer’s preference to pay with cash when the product arrives at their doors.</li><li><strong>COD</strong> is considered a risky payment method, that is why we need to add an alternative payment method like bank transfer or other payment gateways that are used by our customers.</li><li>Applying vouchers or discounts to the payment methods can help customers depend on using the COD payment method.</li></ul><p>By diversifying payment options and incentivizing the use of safer, more efficient methods, businesses can not only reduce the risks associated with COD but also improve cash flow, streamline operations, and enhance the overall customer experience.</p><p><strong>Identifying and Quantifying Customer Churn to Improve Retention and Loyalty</strong></p><p>This analysis aims to identify and quantify customers who have disengaged from the business over a 90-day period. Understanding churn is critical for addressing retention issues and developing strategies to enhance customer loyalty and reduce churn rates.</p><pre>WITH last_purchase AS (<br>    SELECT<br>        customer_id,<br>        MAX(order_date) AS last_order_date<br>    FROM<br>        order_detail<br>    WHERE<br>        is_valid = 1 -- Only consider valid transactions<br>    GROUP BY <br>        customer_id<br>),<br>customer_status AS (<br>    SELECT<br>        cd.id AS customer_id,<br>        lp.last_order_date,<br>        CURRENT_DATE AS current_date,<br>        CASE<br>            WHEN (CURRENT_DATE - lp.last_order_date) &gt; 90 THEN &#39;churned&#39;<br>            ELSE &#39;active&#39;<br>        END AS churn_status<br>    FROM<br>        customer_detail cd<br>    LEFT JOIN<br>        last_purchase lp<br>    ON<br>        cd.id = lp.customer_id<br>)<br>SELECT<br>    churn_status,<br> COUNT(customer_id) AS customer_count<br>FROM<br>    customer_status<br>GROUP BY<br> churn_status;</pre><blockquote><strong>last_purchase CTE</strong>: Finds the most recent order date for each customer with valid transactions.</blockquote><blockquote><strong>customer_status CTE</strong>: Determines if each customer is &#39;churned&#39; or &#39;active&#39; based on whether their last purchase was more than 90 days ago.</blockquote><blockquote><strong>Final </strong><strong>SELECT</strong>: Counts and groups customers by their churn status (&#39;churned&#39; or &#39;active&#39;) to get the total number of customers in each category.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*8RV5Yx1FgN044TBO1quU5A.png" /></figure><p>Based on our customer churn count results:</p><ul><li><strong>Active Customers</strong>: There are 1,134 active customers, which constitutes 28.44% of the total customer base.</li><li><strong>Churned Customers</strong>: There are 2,864 churned customers, making up 71.56% of the total customer base.</li></ul><p>The findings reveal that a significant portion of the customer base (over 70%) has become inactive, indicating potential gaps in retention efforts. This high churn rate underscores the need for targeted strategies to re-engage inactive customers and foster stronger long-term relationships.</p><p><strong>Implementing cohort analysis for customers in 2021.</strong></p><p>Understanding customer churn is crucial for any business aiming to grow and maintain a loyal customer base. By analyzing the number of customers who have stopped engaging with the business over a 90-day period, this analysis helps uncover potential issues in customer retention.</p><pre>WITH first_invoice AS (<br>    SELECT<br>        customer_id,<br>        MIN(order_date) AS first_transaction<br>    FROM<br>        order_detail<br>    WHERE<br>        EXTRACT(YEAR FROM order_date) = 2021<br>        AND is_valid = 1 -- Only include valid transactions<br>    GROUP BY<br>        customer_id<br>    ORDER BY<br>        first_transaction<br>),<br>cohort_index AS (<br>    SELECT<br>        od.customer_id,<br>        od.order_date,<br>        fi.first_transaction,<br>        EXTRACT(MONTH FROM od.order_date) - EXTRACT(MONTH FROM fi.first_transaction) AS cohort_index<br>    FROM<br>        order_detail AS od<br>    LEFT JOIN <br>        first_invoice AS fi<br>    ON <br>        od.customer_id = fi.customer_id<br>    WHERE<br>        EXTRACT(YEAR FROM od.order_date) = 2021 -- Only include transactions from 2021<br>        AND od.is_valid = 1 -- Only include valid transactions<br>    ORDER BY<br>        od.customer_id, od.order_date<br>),<br>cohort_month AS(<br> SELECT <br>  EXTRACT(MONTH FROM ci.first_transaction) AS cohort_month,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 0 THEN ci.customer_id END) :: numeric AS m0,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 1 THEN ci.customer_id END) :: numeric AS m1,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 2 THEN ci.customer_id END) :: numeric AS m2,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 3 THEN ci.customer_id END) :: numeric AS m3,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 4 THEN ci.customer_id END) :: numeric AS m4,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 5 THEN ci.customer_id END) :: numeric AS m5,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 6 THEN ci.customer_id END) :: numeric AS m6,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 7 THEN ci.customer_id END) :: numeric AS m7,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 8 THEN ci.customer_id END) :: numeric AS m8,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 9 THEN ci.customer_id END) :: numeric AS m9,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 10 THEN ci.customer_id END) :: numeric AS m10,<br>  COUNT(DISTINCT CASE WHEN ci.cohort_index = 11 THEN ci.customer_id END) :: numeric AS m11<br> FROM cohort_index AS ci<br> GROUP BY cohort_month<br> ORDER BY cohort_month<br>)<br>SELECT<br> cm.cohort_month,<br> cm.m0 AS total_new_users,<br> ROUND((m0/m0)*100) AS m0,<br> ROUND((m1/m0)*100) AS m1,<br> ROUND((m2/m0)*100) AS m2,<br> ROUND((m3/m0)*100) AS m3,<br> ROUND((m4/m0)*100) AS m4,<br> ROUND((m5/m0)*100) AS m5,<br> ROUND((m6/m0)*100) AS m6,<br> ROUND((m7/m0)*100) AS m7,<br> ROUND((m8/m0)*100) AS m8,<br> ROUND((m9/m0)*100) AS m9,<br> ROUND((m10/m0)*100) AS m10,<br> ROUND((m11/m0)*100) AS m11<br>FROM cohort_month as cm</pre><blockquote><strong><em>cohort_index</em> CTE</strong>: Calculates how many months after a customer’s first transaction each subsequent purchase occurs, grouping transactions by cohorts.</blockquote><blockquote><strong><em>cohort_month</em> CTE</strong>: Summarizes how many distinct users from each cohort made purchases in the subsequent months.</blockquote><blockquote><strong>Final </strong><strong><em>SELECT</em></strong>: Displays the total new users for each cohort month and the retention rate for each subsequent month in that cohort, helping to track user retention over time.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JxAiYZwhsFX7UDmzngtF3g.png" /></figure><p>There are some insights that we can find from the cohort analysis;</p><ul><li><strong>High Early Churn (Month 1):</strong> Retention drops sharply from 100% to 4%-7% within the first month across all cohorts, indicating significant churn immediately after signup. This suggests potential issues with onboarding, product experience, or unmet expectations.</li><li><strong>Declining Retention After Month 2:</strong> Retention continues to fall after Month 1, with only 2%-12% of users remaining by Month 3. This points to challenges in maintaining user engagement beyond the initial period.</li><li><strong>Inconsistent Long-Term Retention:</strong> Some cohorts, like January and March, show slight retention improvements around Month 6, but overall long-term engagement remains inconsistent, suggesting room for improvement in sustaining interest.</li><li><strong>Mid-Term Retention Improvements (May-July):</strong> Cohorts from May to July show better retention at Month 5–6 (10%-12%), indicating some positive changes during these months, though these improvements are not enough to reverse the overall downward trend.</li></ul><p><strong>Actionable Takeaways</strong></p><ul><li><strong>Improve Early Retention:</strong> Focus on enhancing the onboarding process and understanding early churn drivers to keep users engaged during the critical first month.</li><li><strong>Boost Engagement Beyond Month 2:</strong> Implement strategies like personalized experiences or incentives to increase product value and keep users engaged longer.</li><li><strong>Target Specific Cohorts for Interventions:</strong> Focus on cohorts with the highest churn (e.g., February, March, October) with tailored campaigns or adjustments to improve retention.</li><li><strong>Replicate Successful Strategies:</strong> Analyze the cohorts with improved retention (e.g., May, June) to identify factors that contributed to better performance, and apply them to other months.</li></ul><p><strong>Conclusion</strong></p><p>This analysis highlights valuable insights to drive business growth. By understanding seasonal sales trends, we can capitalize on high-demand periods like August and December with targeted promotions and better inventory planning while addressing slower months like March and April with strategic marketing. Customer retention analysis reveals opportunities to improve onboarding and long-term engagement, especially given the significant early churn rates. Lastly, analyzing payment preferences, such as the heavy reliance on Cash on Delivery, underscores the need for diversifying payment methods and incentivizing safer, more efficient options to reduce risk and enhance customer experience.</p><p>For me, this analysis highlights the importance of using data to make informed decisions — something I’m passionate about as I continue to explore the world of data analysis. These actionable strategies not only help businesses grow but also help me apply my learning to real-world challenges, bringing data-driven decisions to life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5da9eb91525f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>