<?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 Vicky Mahfudy on Medium]]></title>
        <description><![CDATA[Stories by Vicky Mahfudy on Medium]]></description>
        <link>https://medium.com/@vickymahfudy?source=rss-7bfd443c5780------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lRkaobnqMRILSFl2bhP7Zg.jpeg</url>
            <title>Stories by Vicky Mahfudy on Medium</title>
            <link>https://medium.com/@vickymahfudy?source=rss-7bfd443c5780------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 05:01:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vickymahfudy/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[Project Data Analysis for B2B Retail — XYZ.com Customer Analytics Report]]></title>
            <link>https://medium.com/@vickymahfudy/project-data-analysis-for-b2b-retail-xyz-com-customer-analytics-report-f7b6f775f28c?source=rss-7bfd443c5780------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7b6f775f28c</guid>
            <category><![CDATA[cte]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[window-functions]]></category>
            <category><![CDATA[customer-analytics]]></category>
            <category><![CDATA[data-analytics]]></category>
            <dc:creator><![CDATA[Vicky Mahfudy]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 05:47:08 GMT</pubDate>
            <atom:updated>2022-04-16T05:47:08.443Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nln1NoYG3oWeY4rNgRhRYg.png" /></figure><h3><strong>Project Data Analysis for B2B Retail — XYZ.com Customer Analytics Report</strong></h3><h4><strong>Using CTE and Window Function in SQL<br></strong>by Vicky Mahfudy</h4><h3>Overview</h3><p>DQLab is a Self-Paced Online Data Learning Center for data practitioners who want to brush up theirs skills. This project is part of their curriculum in order to build analytical skills and apply it to industry real problems. In this project, DQLab and Trisna Yulia Junita, a Data Scientist at PT. BUMA, provides a study case to learn customer behavior at a business-to-business (B2B)<strong> </strong>startup called XYZ.com.</p><p>A B2B transaction is conducted between two companies, such as wholesalers and online retailers. Every quarter, xyz.com evaluates their sales performance. One of the things they do is to explore the habits of their customers. Xyz.com is a data-driven company, every decision making must be based on existing data. This time, xyz.com will create a Customer Analytics Report based on sales data for the last 6 months (2 quaters). We will use CTE and Window Function in SQL to retrieve the data and do some calculation and aggregation to answer the questions.</p><h3>Key Metrics</h3><p>The analytical indicators used in this Customer Analytics Report are as follows:<br>1. How is the current sales growth?<br>2. Is the number of xyz.com customers growing?<br>3. How many of these customers have made transactions?<br>4. What product categories are most purchased by customers?<br>5. How many customers are still actively transacting?</p><h3>Data Understanding</h3><p>Before starting to compose SQL queries and make analysis of the query results, the first thing that needs to be done is to become familiar with the tables that will be used. It will be very useful in determining which columns are related to the problem to be analyzed, and what data manipulation process should be done for these columns, because not all columns in the table need to be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*AQXMvUYW_gzO9bFErkwyeA.png" /></figure><p>The data consists of several interrelated tables:</p><p><strong>orders_1<br></strong>Contains sales transactions data on the first quarter (Q1) with total 244 records.<br>(Jan — Mar 2004)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RMojxm80E8_cS4Uv-_snlA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgBSQnSPdcnXzRCbh0HWFQ.png" /></figure><p><strong>orders_2<br></strong>Contains sales transactions data on the second quarter (Q2) with total 244 records.<br>(Apr — Jun 2004)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwx_5ZcyUij3wsmWyJKtmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9LfhwRkvAFrdZTuAPQKVQ.png" /></figure><p><strong>customer</strong><br>Contains data of registered customer at xyz.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*bCXNu88fGgD6S47w2Q6dmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*scrx8ps4ZR4B9LWxJWzZ6A.png" /></figure><h3>Preparation</h3><p>Common Table Expression (CTE) allows you to define a temporary named result set that available temporarily in the execution scope of a statement such as <a href="https://www.sqlservertutorial.net/sql-server-basics/sql-server-select/"><strong>SELECT</strong></a>, <a href="https://www.sqlservertutorial.net/sql-server-basics/sql-server-insert/"><strong>INSERT</strong></a>, <a href="https://www.sqlservertutorial.net/sql-server-basics/sql-server-update/"><strong>UPDATE</strong></a>, <a href="https://www.sqlservertutorial.net/sql-server-basics/sql-server-delete/"><strong>DELETE</strong></a>, or <a href="https://www.sqlservertutorial.net/sql-server-basics/sql-server-merge/"><strong>MERGE</strong></a>. CTE will be very helpful when we want to create a sub-query that will be used again in the next query. With CTE, we don’t need to rewrite the sub-query, we just need to call the alias name of the CTE table. Use <strong>WITH </strong>clause followed by the <strong>alias name</strong> of the CTE and then <strong>AS </strong>clause to create one or more CTE.</p><p>Therefore, we will combine all sales data on Q1 in the <strong>orders_1 </strong>table and sales on Q2 in the <strong>orders_2 </strong>table, to make it easier to calculate overall summarize and aggregate calculations. Use <strong>UNION </strong>clause to combine the data become one table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*oK_a2cW7657UC0YCIF_MmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/109/1*7eMNgeLvXCzeJuitR9DvkQ.png" /><figcaption>The combined data has 490 record</figcaption></figure><p>After this, we can use this CTE in the next query by simply calling the alias name of the CTE, which is ‘<strong>orders_q1_q2</strong>’</p><h3>Sales and Revenue Analysis</h3><p>First thing first, before we do in-depth analysis of the customer, we must understand the overall sales first. So we can find the problem from it. <br>For example:</p><p>- <strong>When sales increase<br></strong>1. Is the number of our customers increasing?<br>2. How many customers do repeat order?<br>3. What categories experienced an increase in sales?</p><p>- <strong>When sales experience a decline</strong><br>1. Is there no addition of new customers in Q2?<br>2. How many customers who only make purchases in Q1?<br>3. What categories can help our sales in the future?</p><h4>A. Total Sales and Revenue on Each Quarter</h4><p>To find out our sales growth, first calculate the total sales and total revenue in each quarter. We have to filter our data by only those orders that have been sent, those with <strong>status </strong>= ‘<strong>Shipped</strong>’. Use our CTE table that we created before by call ‘<strong>orders_q1_q2</strong>’.</p><blockquote>Save the result as a new CTE for reuse in the next query</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*bVY1o0z-CnP_6BGaXCOvMA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*Popsa_DE9cXZAQMsi_k9_g.png" /></figure><p>Based on the results above, it can be seen that the total sales in Q2 were less than the Q1. There was a decreasing total sales in Q2. This will also affect the company’s total revenue, so it decreased too.</p><h4>B. Sales Growth Percentage and Revenue Growth Percentage</h4><p>The formula for calculating the percentage of sales growth and the percentage of revenue growth is as follows:</p><blockquote><strong>%Sales Growth</strong> = (total_sales q2-total_sales q1)/total_sales q1<br><strong>%Revenue Growth</strong> = (total_revenue q2–total_revenue q1)/ total_revenue q1</blockquote><p>To find the difference between q1 and q2, we can use one of the <strong>window functions</strong> in SQL, called <strong>LAG()</strong>. Window functions are those functions which perform operations for each row of the partition or window. These functions produce the result for each query row unlikely to the aggregate functions that group them and results in a single row. The <strong>LAG()</strong> function is used to get value from row that precedes the current row. This function is followed by the <strong>OVER() </strong>function to define how rows are partitioned into groups. If <strong>OVER() </strong>is empty then function compute result using all rows. The implementation is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*vaG-xC3rbTRlI6dc2_pDfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*P1nJN-m_E7e14FssWvjJSA.png" /></figure><p>The result shows that the performance of XYZ.com experienced a very significant decrease by almost <strong>-23%</strong> for <strong>sales growth</strong>, and <strong>-24%</strong> for <strong>revenue growth</strong>. From this data, we can conduct a deeper analysis of the causes of our decline in sales. One of it is by doing a customer analytics.</p><h3><strong>Customer Analytics</strong></h3><p>As I mentioned earlier, when sales growth experienced a decline, we have to find the causes. We can start from looking at the growth in the number of our customers, the retention rate and churn rate, and what category whose sales are still high so we can focus on developing it.</p><h4>A. Total Registered Customer on Each Quarter</h4><p>Since the company’s sales have decreased, we can check whether this is due to a decrease in our customers or not. We can count the number of new user who create accounts at xyz.com in each quarter.</p><blockquote>Save the result using CTE for reuse in the next query</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*4WPDvL2bBqNzrc0jSSttZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*GoepUVYYmx_tJUmAa4DhuA.png" /></figure><p>It turned out that there was a decrease in the number of new users in Q2. This could be one of the reasons of the decreased sales. New users will open new customer segments as well who might be able to buy product which still have small sales. The marketing team must push back promotional activities again to attract new users.</p><h4>B. Customer Who Made Order Completely</h4><p>Of course, not all users who create accounts at xyz.com make order completely. There are some customers who are just scrolling through the catalog, some are just looking for price references, some are having payment problems so they cancel their orders, etc. So we also have to know the percentage of the number of users who made order completely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*xweS5XT_0NO3Mgm9StTyFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*wRQREKlfhvxZv4pPbQwYOQ.png" /></figure><p>The number of customers who place orders has also decreased. Furthermore, we can also see the percentage of the number of customers who place orders over the total number of customers by combining the 2 CTE’s that we created above by using <strong>JOIN </strong>clause, and make a new calculated collumn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*R6N3Jtd7FjOzclRMk7fZ_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*qBG0iaSueTlCFAhWI4wraA.png" /></figure><p>The <strong>interest of the customers</strong> to do shoping at xyz.com is still <strong>lacking</strong>, only between <strong>54% - 58%</strong> have made transactions. There are several things that could be the causes:</p><p><strong>Non-Technical Causes:<br>-</strong> The product is not attractive<br>- Price is too high<br>- Lack of testimonials</p><p><strong>Technical Causes:<br>-</strong> The Application is slow<br>- Checkout process is too complicated<br>- Less payment options</p><p>The teams associated with the possible problems above must do checking, so the root cause of the problem can be found and immediately repaired.</p><h4>C. Summarize by Category in Q2</h4><p>To check the non-technical problems, we can do a breakdown by looking at which categories are still in high demand and which category has the lowest sales, so we can immediately take action to increase or maintain the sales of that category.</p><blockquote>Save the result using CTE for reuse in the next query</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*IjRQwtDQJslde8EJXS692A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*v_V2-irU_4ZjMeZwqDUKeA.png" /></figure><p>From these results, we can detail the information we want to show by adding percent of total orders and percent of total sales in Q2. So that we can find out the proportion of sales from each category.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*kfr400SKUKvskPzJOxHRJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*wDCaKHqnqoiwgFhcD0K3wg.png" /></figure><p>It can be seen that categories <strong>S28 and S24</strong> experienced large sales <strong>above 20%</strong> of <strong>total sales</strong>. We can provide attractive offers for customers who buy a lot for this product, so that customers will continue to repurchase this product. Otherwise, the <strong>S72 </strong>category had the fewest total sales with only <strong>2%</strong> of <strong>total sales</strong>. There are 3 things we can do with this product:<br>- Conduct product introductions and massive promotions to attract new customers<br>- Improve the quality and appearance of the product<br>- Stop selling these items because it maybe rarely needed by customers.</p><h4>D. Retention Rate and Churn Rate</h4><p>Retention rate refers to the percentage of customers who continue paying for a product over a given timeframe. In this case, we want to see what percentage of our customers make other purchases in the next quarter. While churn rate is the measure of how many customers stop using a product. In this case, the churn customer do no more transactions in the next quarter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b1qYvr-UPWglpMs2aM5zDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*NVp_t6xAmst8895oL9UT-A.png" /></figure><p>It was found that the <strong>retention rate</strong> of XYZ.com’s customers was <strong>very low</strong> at only <strong>24%</strong>, otherwise, the <strong>churn rate</strong> is <strong>very high</strong> at <strong>76%</strong>. Meaning that a lot of customers who had transacted in Q1 did not do order in Q2. Here are some things that can be the causes of that low retention rate:<br>- The product received does not meet expectations<br>- Our products are not updated to current conditions<br>- Customers have unsatisfactory experiences in purchasing, for example, shipping order that are too long</p><h4>E. Delayed Shipped Time</h4><p>One of the possible reasons why customers not doing repurchase is the slow process of product delivery. We can check it by calculating the average product delivery on their orders, whether the delivery is too long or still classified as normal. We can use the <strong>orderDate </strong>and <strong>shippedDate </strong>field by finding the difference in days from those fields, then aggregated the average.</p><p>To find the difference in days between <strong>orderDate </strong>and <strong>shippedDate</strong>, we can use one of the functions already available in SQL, namely <strong>DATEDIFF()</strong>. This function returns the difference between two dates. To ensure that the resulting calculation is positive, we can add the <strong>ABS()</strong> function outside of the <strong>DATEDIFF()</strong> call.</p><p>It is assumed that the delayed delivery time is more than 3 days. So we have to filter the aggregation results by using the <strong>HAVING </strong>clause followed by the condition, in this case those that have an average delivery more than 3 days.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BAqE-8AP4-tj0C6X-h-NQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*Qaot8-fuOBLYY1vuro079A.png" /></figure><p>It can be seen that <strong>8</strong> customers <strong>experienced delayed delivery</strong>. This could be one of the reasons they left our company. The delivery team must immediately check whether the delay in delivery is our fault or the expedition’s fault. If it turns out to be our fault, we must immediately fix it so that there are no more delays in the future.</p><h3>Conclusions</h3><p>Based on the results of the analysis that has been done, it can be concluded as follows:</p><ol><li>The result shows that the performance of XYZ.com experienced a very significant decrease by almost <strong>-23%</strong> for <strong>sales growth</strong>, and <strong>-24%</strong> for <strong>revenue growth</strong>.</li><li>It turned out that there was a <strong>decrease </strong>in the number of <strong>new users</strong> in Q2, from <strong>43 </strong>to <strong>35</strong>. This could be one of the reasons of the decreased sales. The marketing team must push back promotional activities again to attract new users.</li><li>The <strong>interest of the customers </strong>to do shoping at xyz.com is still <strong>lacking</strong>, only beetween <strong>54% - 58%</strong> have made transactions. The teams associated with the possible problems (technical and non-technical), must do checking, so the root cause of the problem can be found and immediately repaired.</li><li>In Q2, categories <strong>S28 </strong>and <strong>S24 </strong>experienced large sales <strong>above 20% </strong>of <strong>total sales</strong>. We can provide attractive offers for customers who buy a lot for this product, so that customers will continue to repurchase this product. Otherwise, the <strong>S72 </strong>category had the fewest total sales with only <strong>2% </strong>of <strong>total sales</strong>. Things that can be done to fix it is improving the quality of the product or stop selling the product.</li><li>It was found that the <strong>retention rate</strong> of XYZ.com’s customers was <strong>very low</strong> at only <strong>24%</strong>, otherwise, the <strong>churn rate</strong> is <strong>very high</strong> at <strong>76%</strong>. Meaning that a lot of customers who had transacted in Q1 did not do order in Q2. Maybe there are several possible technical problems experienced by customers, such as a slow application or difficulty in payment process, so that customers are reluctant to make purchases again. The marketing team must do a survey for this customer, so we can so we can quickly find out the causes.</li><li>There are<strong> 8</strong> customers <strong>experienced delayed delivery</strong>. This could be one of the reasons they left our company. The delivery team must immediately check whether the delay in delivery is our fault or the expedition’s fault. If it turns out to be our fault, we must immediately fix it so that there are no more delays in the future.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7b6f775f28c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>