<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Beverline Otiende</title>
    <description>The latest articles on Forem by Beverline Otiende (@beverline_otiende_6d3045c).</description>
    <link>https://forem.com/beverline_otiende_6d3045c</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3715446%2F2d982587-bf8c-4632-bf04-1a0bbbdb6bd1.png</url>
      <title>Forem: Beverline Otiende</title>
      <link>https://forem.com/beverline_otiende_6d3045c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/beverline_otiende_6d3045c"/>
    <language>en</language>
    <item>
      <title>Connecting PowerBI to a PostgreSQL database</title>
      <dc:creator>Beverline Otiende</dc:creator>
      <pubDate>Sun, 29 Mar 2026 03:15:44 +0000</pubDate>
      <link>https://forem.com/beverline_otiende_6d3045c/connecting-powerbi-to-a-postgresql-database-bpi</link>
      <guid>https://forem.com/beverline_otiende_6d3045c/connecting-powerbi-to-a-postgresql-database-bpi</guid>
      <description>&lt;p&gt;PowerBI is a business intelligence (BI) tool developed by Microsoft, designed to help users visualize data, create interactive dashboards and make informed decisions.&lt;br&gt;
It is widely used across industries because it simplifies complex data and presents it in a visually compelling way.&lt;br&gt;
PowerBI enables data analysts to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect to multiple data sources&lt;/li&gt;
&lt;li&gt;Transform and clean data&lt;/li&gt;
&lt;li&gt;Do Data modelling&lt;/li&gt;
&lt;li&gt;Build interactive dashboards and reports&lt;/li&gt;
&lt;li&gt;Share insights across teams and organizations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the strengths of PowerBI is its ability to connect to multiple data sources, particularly SQL databases.&lt;/p&gt;

&lt;p&gt;SQL (Structured Query Language) databases are the backbone of modern data storage systems. &lt;br&gt;
SQL databases are very essential because they:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store large volumes of structured data&lt;/li&gt;
&lt;li&gt;Ensure data integrity and consistency&lt;/li&gt;
&lt;li&gt;Allow efficient querying and data retrieval&lt;/li&gt;
&lt;li&gt;Support complex analytical operations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By connecting PowerBI to SQL databases, companies can unlock real-time insights, improve data accuracy and streamline their analytics workflow.&lt;/p&gt;

&lt;p&gt;In this article, we will walk through how to connect Power BI to both a local PostgreSQL database and a cloud-hosted PostgreSQL database (Aiven), and how to model your data effectively inside Power BI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Connecting PowerBI to a local PostgreSQL database&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Let us first see how to connect PowerBI to a local PostgreSQL database.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 1: Open Power BI Desktop Application&lt;/em&gt;&lt;br&gt;
Launch Power BI Desktop on your computer if you have it installed. If not you can download it from the Microsoft store here &lt;a href="https://apps.microsoft.com/detail/9ntxr16hnw1t?hl=en-US&amp;amp;gl=US" rel="noopener noreferrer"&gt;PowerBI Desktop download link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4bkl6rx128e2pbiomvs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4bkl6rx128e2pbiomvs.png" alt="PowerBI desktop" width="228" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 2: Click “Get Data”&lt;/em&gt;&lt;br&gt;
On the Home ribbon, click Get Data to view all available data sources.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqczrcq646k0tw3l0npzn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqczrcq646k0tw3l0npzn.png" alt="Home ribbon, Get Data" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 3: Select PostgreSQL Database&lt;/em&gt;&lt;br&gt;
Choose the database category, then select PostgreSQL Database&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flnxufj8aposzdmcorpeu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flnxufj8aposzdmcorpeu.png" alt="select PostgreSQL Database" width="800" height="427"&gt;&lt;/a&gt;&lt;br&gt;
After selecting the PostgreSQL, press Connect.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 4: Enter Connection Details&lt;/em&gt;&lt;br&gt;
After pressing Connect, you will be prompted to enter your postgreSQL connection details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6v5oi6my0n3aspsd9p3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6v5oi6my0n3aspsd9p3m.png" alt="Connection details required" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will  have to check your local postgreSQL connection to check on the connection details i.e; right click on your database then select Edit connection, it will bring you to this page;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6772bemunteeyerkn6my.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6772bemunteeyerkn6my.jpg" alt="Local postgreSQL connection" width="800" height="594"&gt;&lt;/a&gt;&lt;br&gt;
From this page you are able to get the server name(host), database, port and other information.&lt;br&gt;
&lt;strong&gt;Server&lt;/strong&gt;: localhost:5432 (you put your server name:then port)&lt;br&gt;
&lt;strong&gt;Database&lt;/strong&gt;: your database name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnysgan9umgw33v6oulr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhnysgan9umgw33v6oulr.png" alt="Enter server name and database name" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After putting your server name and database name, click OK.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 5: Provide Credentials&lt;/em&gt;&lt;br&gt;
Then Enter your Username and password from your local postgreSQL connection.&lt;br&gt;
It should look like this;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0s52khtf1tbvyaua64ny.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0s52khtf1tbvyaua64ny.png" alt="Entering username and password" width="800" height="426"&gt;&lt;/a&gt;&lt;br&gt;
Then Click Connect.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 6: Load Data&lt;/em&gt;&lt;br&gt;
After Clicking Connect, Power BI will display a Navigator window showing available tables on the left.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk20sds4itpdejvdsnyil.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk20sds4itpdejvdsnyil.png" alt="PowerBI Navigation window" width="800" height="575"&gt;&lt;/a&gt;&lt;br&gt;
Select the tables you need by ticking their respective checkboxes.&lt;br&gt;
For me I'm choosing the tables;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;customers&lt;/li&gt;
&lt;li&gt;products&lt;/li&gt;
&lt;li&gt;sales&lt;/li&gt;
&lt;li&gt;inventory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My selected tables have "assignment." before their names because they are in a schema called assignment. &lt;/p&gt;

&lt;p&gt;After selecting your tables, you can choose to load&lt;br&gt;
or Transform Data or Cancel depending on what you want to with the data first.&lt;br&gt;
For my case I'm selecting Load.&lt;br&gt;
After Selecting Load, the tables then get loaded to your PowerBI and you can be able to perform data cleaning, data validation, data modelling, data analysis and visualization.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8tbi64dgzocls5k4i8b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8tbi64dgzocls5k4i8b.jpg" alt="Tables in PowerBI" width="800" height="585"&gt;&lt;/a&gt;&lt;br&gt;
You can navigate from the right side to select your tables and work on them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Connecting PowerBI to a cloud database-Aiven PostgreSQL database&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Cloud databases are increasingly popular today because they allow us to have remote access to our databases, ensure scalability and ensure high availability of our databases.&lt;br&gt;
Aiven provides managed PostgreSQL services in the cloud.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Step 1: Go to Aiven and check for your PostgreSQL database connection if you have one. If you don't have one then create a new database connection.&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foz4uq3m4lo5toirpsg8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foz4uq3m4lo5toirpsg8g.png" alt="aiven PostgreSQL connection" width="800" height="379"&gt;&lt;/a&gt;&lt;br&gt;
If you have a connection, open it, if you don't have one then Create service from the top right corner.&lt;br&gt;
Open your SQL connection from Aiven by double clicking it. Then go to Connection information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9ea6o6m8yxvogkzkjbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9ea6o6m8yxvogkzkjbn.png" alt="Aiven PostgreSQL connection information" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the Connection Information, check for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Host (e.g., your-db.aivencloud.com)&lt;/li&gt;
&lt;li&gt;Port &lt;/li&gt;
&lt;li&gt;Database name&lt;/li&gt;
&lt;li&gt;Username&lt;/li&gt;
&lt;li&gt;Password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Step 2: Download SSL Certificate&lt;/u&gt;&lt;/em&gt;&lt;br&gt;
Aiven enforces secure connections using SSL (Secure Sockets layer). &lt;br&gt;
Download the CA Certificate (usually a .pem file) from your Aiven service dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcicuyivm9i8qj9dmu821.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcicuyivm9i8qj9dmu821.png" alt="Downloading CA certificate" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking the CA certificate download, it will be downloaded and you have to save it in a secure and accessible location on your computer.&lt;br&gt;
SSL is Important because it ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data encryption during transmission&lt;/li&gt;
&lt;li&gt;Protection against unauthorized access&lt;/li&gt;
&lt;li&gt;Secure communication between Power BI and the cloud database.
Without SSL, your data could be exposed to security risks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Step 3: Install PostgreSQL ODBC Driver&lt;/u&gt;&lt;/em&gt;&lt;br&gt;
To be able to connect PowerBI to an aiven PostgreSQL database, you need a PostgreSQL ODBC Driver.&lt;br&gt;
You can download it using the link &lt;a href="https://www.postgresql.org/ftp/odbc/releases/REL-17_00_0008-mimalloc/" rel="noopener noreferrer"&gt;Download PostgreSQL ODBC Driver here&lt;/a&gt;&lt;br&gt;
After installing in, open the ODBC Data Sources from your computer. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Step 4: Create an ODBC connection&lt;/u&gt;&lt;/em&gt;&lt;br&gt;
After opening ODBC Data Sources &lt;br&gt;
Go to System DSN then click Add&lt;br&gt;
Select PostgreSQL Unicode(x64)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc1kwgb4yheyahvgz60i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc1kwgb4yheyahvgz60i.png" alt="Selecting PostgreSQL Unicode(x64)" width="580" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click Finish then it will open up the window below.&lt;br&gt;
Input your connection details from your Aiven PostgreSQL database as shown below;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k7r4q4v1343co1d0uxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k7r4q4v1343co1d0uxy.png" alt=" " width="592" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Step 5: Configure SSL&lt;/u&gt;&lt;br&gt;
Enable SSL mode by Setting &lt;strong&gt;SSL Mode&lt;/strong&gt; to &lt;strong&gt;require&lt;/strong&gt;&lt;br&gt;
Provide the certificate file path if required&lt;/p&gt;

&lt;p&gt;Click Test to see if your connection is Okay. If Connection is okay, proceed and save. If not recheck your connection details&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw96q3gugxx8q89zp41ar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw96q3gugxx8q89zp41ar.png" alt="Testing connection" width="592" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;u&gt;Step 6: Launch PowerBI and Get data from your ODBC&lt;/u&gt;&lt;/em&gt; &lt;br&gt;
After saving, close it the go and open your PowerBI desktop.&lt;br&gt;
Go to &lt;strong&gt;Get Data&lt;/strong&gt; and search for &lt;strong&gt;ODBC&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj86af1cc3oa98wvlmb6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj86af1cc3oa98wvlmb6z.png" alt="Select ODBC" width="800" height="588"&gt;&lt;/a&gt;&lt;br&gt;
Select ODBC and click Connect&lt;br&gt;
Select your Data source Name and click okay&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1skxv4r9ope8sgdn95id.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1skxv4r9ope8sgdn95id.png" alt="selecting Data source Name" width="800" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then input your username and password from your Aiven connection then press Connect.&lt;br&gt;
&lt;em&gt;&lt;u&gt;Step 6: Select your tables from the Navigator&lt;/u&gt;&lt;/em&gt; &lt;br&gt;
A navigator window will open up. Then choose the schema where your tables are and then select your tables. For me my schema is assignment and my tables are Customers, inventory, products and sales.&lt;br&gt;
Click Load to load your tables.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Loading tables in PowerBI and creating relationships&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
After loading the tables, PowerBI automatically detects the relationships between the tables based on shared columns. &lt;br&gt;
However it is necessary to verify these relationships before working on the data to ensure accuracy.&lt;/p&gt;

&lt;p&gt;For my case, I have four tables;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers table: stores customer information&lt;/li&gt;
&lt;li&gt;Products table: contains products details&lt;/li&gt;
&lt;li&gt;Sales table: records sales transactions&lt;/li&gt;
&lt;li&gt;Inventory table: tracks stocks levels&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To create relationship between tables in PowerBI;&lt;br&gt;
Launch your PowerBI desktop if you haven’t.&lt;br&gt;
Go to the Modelling tab in your PowerBI and select Manage Relationships.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5xstrb8bl1hzcoey5cv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5xstrb8bl1hzcoey5cv.png" alt="Select manage Relationships" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check the relationships if they are okay and select the relationship you want to edit if any then click edit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23o3exv85njh7cwna1m6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23o3exv85njh7cwna1m6.png" alt="Edit relationships" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Edit the relationship appropriately then Save.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffselxm8ve2dmu90sfasp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffselxm8ve2dmu90sfasp.png" alt="Edit relationship" width="800" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Proper relationships in PowerBI are important because they allow analysts to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Join tables correctly.&lt;/li&gt;
&lt;li&gt;Aggregate data accurately.&lt;/li&gt;
&lt;li&gt;Enable filtering across visuals.&lt;/li&gt;
&lt;li&gt;Build meaningful dashboards.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Importance of SQL skills for PowerBI analysts&lt;/strong&gt;&lt;br&gt;
While PowerBI is a powerful visualization tool, SQL remains a critical skill for any data analysts.&lt;br&gt;
SQL helps analysts to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieve data efficiently from databases&lt;/li&gt;
&lt;li&gt;Filter datasets using conditions&lt;/li&gt;
&lt;li&gt;Perform aggregations&lt;/li&gt;
&lt;li&gt;Join multiple tables&lt;/li&gt;
&lt;li&gt;Prepare clean datasets before importing into PowerBI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In real world scenarios, analysts rarely use raw data directly. Instead they Use SQL to extract and shape data, Load the data into PowerBI then they build dashboards and generate insights from the data. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Conclusion&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
PowerBI and SQL databases together form a powerful combination for data analysis and business intelligence.&lt;br&gt;
SQL databases provide a reliable and structured way to store and manage data whereas PowerBI transforms that data into clear and interactive insights that support data driven decision making.&lt;br&gt;
Being able to connect Power BI and SQL together gives analysts a competitive advantage and organizations that leverage on this integration make smarter, faster and more informed decisions, which translate to better outcomes and sustained growth.&lt;/p&gt;

</description>
      <category>database</category>
      <category>microsoft</category>
      <category>postgres</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Advanced SQL for Data Analytics: Advanced Techniques Every Data Analyst Should Know</title>
      <dc:creator>Beverline Otiende</dc:creator>
      <pubDate>Sun, 22 Mar 2026 12:29:08 +0000</pubDate>
      <link>https://forem.com/beverline_otiende_6d3045c/advanced-sql-for-data-analytics-advanced-techniques-every-data-analyst-should-know-3k3h</link>
      <guid>https://forem.com/beverline_otiende_6d3045c/advanced-sql-for-data-analytics-advanced-techniques-every-data-analyst-should-know-3k3h</guid>
      <description>&lt;p&gt;In today’s data-driven world, many organizations heavily rely on data to help them make informed decisions, to optimize their operations and to help them gain a competitive advantage over their competitors. &lt;br&gt;
At the heart of this data reliance and transformation lies SQL (Structured Query Language), which is the fundamental tool used to interact with relational databases.&lt;br&gt;
SQL is the backbone of data analytics because most business data is usually stored in relational databases such as PostgreSQL, MySQL or Microsoft SQL Server. &lt;/p&gt;

&lt;p&gt;Data analysts use SQL to:&lt;br&gt;
•Retrieve data for reporting and dashboards&lt;br&gt;
•Clean and transform raw data&lt;br&gt;
•Perform aggregations and calculations&lt;br&gt;
•Analyze trends and patterns&lt;br&gt;
•Support decision-making processes&lt;/p&gt;

&lt;p&gt;While basic SQL skills such as creating databases and tables, inserting data into tables, updating tables and deleting from tables are essential, they are not enough to handle the complexity of real world data problems.&lt;br&gt;
Advanced SQL techniques are required to help data analysts to extract deeper insights, handle large datasets efficiently and solve complex business challenges. &lt;br&gt;
These advanced SQL techniques go beyond simple queries and include concepts such as &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Joins&lt;/li&gt;
&lt;li&gt; Window functions &lt;/li&gt;
&lt;li&gt; Common Table Expressions (CTEs) &lt;/li&gt;
&lt;li&gt; Subqueries &lt;/li&gt;
&lt;li&gt; Stored Procedures&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this article, I explore more about these advanced SQL techniques and how they are applied in real-world data analytics scenarios. &lt;br&gt;
This article is designed to help beginners understand not just the syntax, but also the practical application of these techniques in business environments.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;u&gt;&lt;strong&gt;JOINS&lt;/strong&gt;&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Joins in SQL allow analysts to combine data from different tables into one result set based on a related column.&lt;/p&gt;

&lt;p&gt;Let us use these two tables below (Products table and Purchases table) to understand more about the different types of SQL Joins.&lt;/p&gt;

&lt;p&gt;Below is the products table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;products Table
| # | Product ID | Product Name | Price  |
| - | ---------- | ------------ | ------ |
| 1 | 1          | Laptop       | 55,000 |
| 2 | 2          | Phone        | 10,000 |
| 3 | 3          | Charger      | 2,000  |
| 4 | 4          | Mouse        | 500    |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is the purchases table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;purchases table
| # | sale_id  |product_id| quantity | total_purchase |       |
| - | --------| -------- | --------- | -------------- |
| 1 | 1       | 1        | 2         | 110,000        |
| 2 | 2       | 2        | 3         | 30,000         |
| 3 | 3       | 3        | 2         | 4,000          |
| 4 | 4       | [NULL]   | 1         | 3,500          |
| 5 | 5       | [NULL]   | 4         | 25,000         |
| 6 | 6       | [NULL]   | 5         | 70,000         |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Types of SQL Joins&lt;/u&gt;&lt;br&gt;
a)  &lt;strong&gt;INNER JOIN&lt;/strong&gt;&lt;br&gt;
Inner Join only returns rows that have matching values in both tables being joined.&lt;/p&gt;

&lt;p&gt;E.g. we can check for rows with matching values from our products and purchases tables using the sql query below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; 
 &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
 &lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;purchases&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this INNER Join query above, you get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| # | product_id | product_name | price  | sale_id | product_id | quantity | total_purchase |
| - | ---------- | ------------ | ------ | ------- | ---------- | -------- | -------------- |
| 1 | 1          | Laptop       | 55,000 | 1       | 1          | 2        | 110,000        |
| 2 | 2          | Phone        | 10,000 | 2       | 2          | 3        | 30,000         |
| 3 | 3          | Charger      | 2,000  | 3       | 3          | 2        | 4,000          |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b)  &lt;strong&gt;LEFT JOIN (LEFT OUTER JOIN)&lt;/strong&gt;&lt;br&gt;
Left Joins returns all the rows from the left table (first table selected) and matching rows from the right table (second table).&lt;br&gt;
If there is no match from the right table, it fills with NULL.&lt;/p&gt;

&lt;p&gt;For example lets check for all the rows and columns from the products table and only the corresponding matching values from the purchases table.  we perform a Left Join using the query below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;purchases&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
   &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this Left Join we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| # | product_id | product_name | price  | sale_id | product_id | quantity | total_purchase |
| - | ---------- | ------------ | ------ | ------- | ---------- | -------- | -------------- |
| 1 | 1          | Laptop       | 55,000 | 1       | 1          | 2        | 110,000        |
| 2 | 2          | Phone        | 10,000 | 2       | 2          | 3        | 30,000         |
| 3 | 3          | Charger      | 2,000  | 3       | 3          | 2        | 4,000          |
| 4 | 4          | Mouse        | 500    | [NULL]  | [NULL]     | [NULL]   | [NULL]         |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c)  &lt;strong&gt;RIGHT JOIN (RIGHT OUTER JOIN)&lt;/strong&gt;&lt;br&gt;
Right Joins returns all the rows from the right table (second table selected) and matching rows from the left table (first table).&lt;br&gt;
If there is no match from the left table, it fills with NULL.&lt;/p&gt;

&lt;p&gt;For example we can do a Right Join to get the corresponding rows from the products table and all the rows from the purchases table using the query below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
&lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;purchases&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
   &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this right join, we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| # | product_id | product_name | price  | sale_id | product_id | quantity | total_purchase |
| - | ---------- | ------------ | ------ | ------- | ---------- | -------- | -------------- |
| 1 | 1          | Laptop       | 55,000 | 1       | 1          | 2        | 110,000        |
| 2 | 2          | Phone        | 10,000 | 2       | 2          | 3        | 30,000         |
| 3 | 3          | Charger      | 2,000  | 3       | 3          | 2        | 4,000          |
| 4 | [NULL]     | [NULL]       | [NULL] | 4       | [NULL]     | 1        | 3,500          |
| 5 | [NULL]     | [NULL]       | [NULL] | 5       | [NULL]     | 4        | 25,000         |
| 6 | [NULL]     | [NULL]       | [NULL] | 6       | [NULL]     | 5        | 70,000         |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d)  &lt;strong&gt;FULL JOIN (FULL OUTER JOIN)&lt;/strong&gt;&lt;br&gt;
Full Joins returns all rows from both tables. It is basically a combination of Left Join and Right Join.&lt;/p&gt;

&lt;p&gt;For example lets do a Full Join to find all the rows from both the tables using the syntax below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
&lt;span class="k"&gt;FULL&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;purchases&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
   &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this Full Join we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| # | product_id | product_name | price  | sale_id | product_id | quantity | total_purchase |
| - | ---------- | ------------ | ------ | ------- | ---------- | -------- | -------------- |
| 1 | 1          | Laptop       | 55,000 | 1       | 1          | 2        | 110,000        |
| 2 | 2          | Phone        | 10,000 | 2       | 2          | 3        | 30,000         |
| 3 | 3          | Charger      | 2,000  | 3       | 3          | 2        | 4,000          |
| 4 | [NULL]     | [NULL]       | [NULL] | 4       | [NULL]     | 1        | 3,500          |
| 5 | [NULL]     | [NULL]       | [NULL] | 5       | [NULL]     | 4        | 25,000         |
| 6 | [NULL]     | [NULL]       | [NULL] | 6       | [NULL]     | 5        | 70,000         |
| 7 | 4          | Mouse        | 500    | [NULL]  | [NULL]     | [NULL]   | [NULL]         |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;e)  &lt;strong&gt;CROSS JOIN&lt;/strong&gt;&lt;br&gt;
This returns every combination of rows from both tables and the number of rows multiply.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
&lt;span class="k"&gt;CROSS&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;purchases&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;f)  &lt;strong&gt;SELF JOIN&lt;/strong&gt;&lt;br&gt;
Self Join is when you join a table to itself. You need to use aliases to refer to the same table in two roles&lt;/p&gt;

&lt;p&gt;Lets explore the rest of the advanced sql functions using these 2 tables below.** clients table and sales table**&lt;br&gt;
Here is the clients table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;clients table
| # | client_id | client_name   | city         |
| - | --------- | ------------- | ------------ |
| 1 | 1         | Alice Johnson | New York     |
| 2 | 2         | Bob Smith     | Los Angeles  |
| 3 | 3         | Charlie Brown | Chicago      |
| 4 | 4         | Diana Prince  | Houston      |
| 5 | 5         | Ethan Hunt    | Phoenix      |
| 6 | 6         | Fiona Clark   | Philadelphia |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is the sales table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;sales table
| # | sale_id | client_id | product_name | quantity | sale_amount |
| - | ------- | --------- | ------------ | -------- | ----------- |
| 1 | 1       | 1         | Laptop       | 3        | 75,000      |
| 2 | 2       | 2         | Phone        | 2        | 25,000      |
| 3 | 3       | 3         | Tablet       | 10       | 25,000      |
| 4 | 4       | 4         | Monitor      | 1        | 35,000      |
| 5 | 5       | 5         | Printer      | 7        | 35,000      |
| 6 | 6       | 6         | Keyboard     | 2        | 1,000       |
| 7 | 7       | [NULL]    | Laptop       | 3        | 85,000      |&lt;span class="sb"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;u&gt;WINDOW FUNCTIONS&lt;/u&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Window functions in SQL allow you to perform calculations across a set of rows that are somehow related to the current row without grouping them into a single result.&lt;br&gt;
You can use Window functions to rank rows, calculate cumulative totals or to find the difference between consecutive rows in a dataset.&lt;br&gt;
Unlike like aggregate functions like SUM(), AVG(), COUNT(), MIN(), MAX() which return a single result for a group of rows, Window functions return a value for each row while still providing information from the related rows.&lt;/p&gt;

&lt;p&gt;The basic syntax of Window function include;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PARTITION BY: This splits the data into groups.&lt;/li&gt;
&lt;li&gt;ORDER BY: defines calculation order&lt;/li&gt;
&lt;li&gt;OVER(): defines the window&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Common window functions include:&lt;br&gt;
a)&lt;strong&gt;ROW_NUMBER()&lt;/strong&gt;: This assigns a unique number to each row in the table.&lt;br&gt;
For example lets assign unique row numbers to our sales table and order by sale_amount in descending order. We use the sql query below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;ROW_NUMBER&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_amount&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;row_number&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query, we get unique row numbers assigned to our table as shown below. Even if more than one rows have the same value, they get different row numbers.&lt;br&gt;
We get the assigned row_numbers added as an extra column with numbers 1,2,3,4,5,6,7 as;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_id | product_name | quantity | sale_amount | row_number |
| ------- | --------- | ------------ | -------- | ----------- | ---------- |
| 7       | [NULL]    | Laptop       | 3        | 85,000      | 1          |
| 1       | 1         | Laptop       | 3        | 75,000      | 2          |
| 4       | 4         | Monitor      | 1        | 35,000      | 3          |
| 5       | 5         | Printer      | 7        | 35,000      | 4          |
| 2       | 2         | Phone        | 2        | 25,000      | 5          |
| 3       | 3         | Tablet       | 10       | 25,000      | 6          |
| 6       | 6         | Keyboard     | 2        | 1,000       | 7          |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b)&lt;strong&gt;RANK()&lt;/strong&gt;: This assigns ranks to each rows with ties getting the same rank but leaving gaps in subsequent ranks.&lt;br&gt;
Lets use our sales table to rank our rows and order by sale_amount in descending order.&lt;br&gt;
We use the sql query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_amount&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get a new column rank, and rows with the same sales amount get the same rank value and then there are gaps to subsequent ranks. i.e we get 1, 2, 3, 3, 5,5,7. there is a gap between 3 and 5 because we have two rank 3s. same as for the two rank 5s then rank 7.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_id | product_name | quantity | sale_amount | rank  |
| ------- | --------- | ------------ | -------- | ----------- | ----- |
| 7       | [NULL]    | Laptop       | 3        | 85,000      | 1        |
| 1       | 1         | Laptop       | 3        | 75,000      | 2          |
| 4       | 4         | Monitor      | 1        | 35,000      | 3          |
| 5       | 5         | Printer      | 7        | 35,000      | 3          |
| 2       | 2         | Phone        | 2        | 25,000      | 5          |
| 3       | 3         | Tablet       | 10       | 25,000      | 5          |
| 6       | 6         | Keyboard     | 2        | 1,000       | 7          |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c)&lt;strong&gt;DENSE_RANK()&lt;/strong&gt; : This assigns ranks to each rows with ties getting the same rank but does not leave gaps in subsequent ranks.&lt;br&gt;
Lets use our sales table to dense_rank our rows and order by sale_amount in descending order.&lt;br&gt;
We use the sql query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;DENSE_RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_amount&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;dense_rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get a new column dense_rank, and rows with the same sales amount get the same dense_rank value and there are no gaps to subsequent ranks. i.e we get 1, 2, 3, 3, 4, 4, 5.&lt;br&gt;
From this DENSE_RANK query, we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_id | product_name | quantity | sale_amount | dense_rank |
| ------- | --------- | ------------ | -------- | ----------- | ---------- |
| 7       | [NULL]    | Laptop       | 3        | 85,000      | 1          |
| 1       | 1         | Laptop       | 3        | 75,000      | 2          |
| 4       | 4         | Monitor      | 1        | 35,000      | 3          |
| 5       | 5         | Printer      | 7        | 35,000      | 3          |
| 2       | 2         | Phone        | 2        | 25,000      | 4          |
| 3       | 3         | Tablet       | 10       | 25,000      | 4          |
| 6       | 6         | Keyboard     | 2        | 1,000       | 5          |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d)&lt;strong&gt;LEAD()&lt;/strong&gt;: Allows you to compare the value of the current row with the value of the next row.&lt;br&gt;
To demonstrate LEAD, lets do a Right join on the clients and sales table. Then calculate the lead sale amount and order by sale amount in descending order.&lt;br&gt;
We use the query below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;LEAD&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;next_sale_amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get a new column next_sale_amount and it helps us compare the current sale_amount to the next sale_amount in descending order as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_name   | product_name | sale_amount |next_sale_amount   |
| ------- | ------------- | ------------ | ----------- | ------ |
| 7       | [NULL]        | Laptop       | 85,000      | 75,000 |
| 1       | Alice Johnson | Laptop       | 75,000      | 35,000 |
| 4       | Diana Prince  | Monitor      | 35,000      | 35,000 |
| 5       | Ethan Hunt    | Printer      | 35,000      | 25,000 |
| 2       | Bob Smith     | Phone        | 25,000      | 25,000 |
| 3       | Charlie Brown | Tablet       | 25,000      | 1,000  |
| 6       | Fiona Clark   | Keyboard     | 1,000       | [NULL] |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;e)&lt;strong&gt;LAG()&lt;/strong&gt;: Allows you to compare the value of the current row with the value of the previous row.&lt;br&gt;
To demonstrate LAG, lets do a Right join on the clients and sales table. Then calculate the LAG sale_amount and order by sale_amount in descending order.&lt;br&gt;
We use the query below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="n"&gt;LAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;prev_sale_amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get a new column prev_sale_amount and it helps us compare the current sale_amount to the previous sale_amount in descending order as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_name   | product_name | sale_amount | prev_sale_amount |
| ------- | ------------- | ------------ | ----------- | ---------------- |
| 7       | [NULL]        | Laptop       | 85,000      | [NULL]           |
| 1       | Alice Johnson | Laptop       | 75,000      | 85,000           |
| 4       | Diana Prince  | Monitor      | 35,000      | 75,000           |
| 5       | Ethan Hunt    | Printer      | 35,000      | 35,000           |
| 2       | Bob Smith     | Phone        | 25,000      | 35,000           |
| 3       | Charlie Brown | Tablet       | 25,000      | 25,000           |
| 6       | Fiona Clark   | Keyboard     | 1,000       | 25,000           |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;f)&lt;strong&gt;NTILE()&lt;/strong&gt;: This is used to divide rows into quartiles based on the total.&lt;br&gt;
e.g. NTILE(4) – Divides the total rows into 4 equals parts&lt;br&gt;
       NTILE(10) – Divides total rows into 10 equal parts&lt;br&gt;
Lets divide the sales table into 3 groups and order by quantity,(NTILE(3)). &lt;br&gt;
We use the query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;NTILE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;sale_amount_ntile&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the query we get our sales table divided into 3 quartiles;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_id | product_name | quantity | sale_amount | sale_amount_ntile |
| ------- | --------- | ------------ | -------- | ----------- | ----------------- |
| 3       | 3         | Tablet       | 10       | 25,000      | 1                 |
| 5       | 5         | Printer      | 7        | 35,000      | 1                 |
| 7       | [NULL]    | Laptop       | 3        | 85,000      | 1                 |
| 1       | 1         | Laptop       | 3        | 75,000      | 2                 |
| 2       | 2         | Phone        | 2        | 25,000      | 2                 |
| 6       | 6         | Keyboard     | 2        | 1,000       | 3                 |
| 4       | 4         | Monitor      | 1        | 35,000      | 3                 |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;g)&lt;strong&gt;SUM() OVER()&lt;/strong&gt; : is used to calculate the cumulative sum or partitioned sum of a column across a set of rows while preserving each individual row in a result set.&lt;br&gt;
It allows you to compute running totals or group total without losing the detail of each row.&lt;/p&gt;

&lt;p&gt;For example lets compute the running totals of the sale_amount using the query below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_amount&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;     &lt;span class="n"&gt;rounding_total&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query you get a rounding totals column;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_id | product_name | quantity | sale_amount | rounding_total |
| ------- | --------- | ------------ | -------- | ----------- | -------------- |
| 7       | [NULL]    | Laptop       | 3        | 85,000      | 85,000         |
| 1       | 1         | Laptop       | 3        | 75,000      | 160,000        |
| 4       | 4         | Monitor      | 1        | 35,000      | 230,000        |
| 5       | 5         | Printer      | 7        | 35,000      | 230,000        |
| 2       | 2         | Phone        | 2        | 25,000      | 280,000        |
| 3       | 3         | Tablet       | 10       | 25,000      | 280,000        |
| 6       | 6         | Keyboard     | 2        | 1,000       | 281,000        |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;h)&lt;strong&gt;PARTITION BY()&lt;/strong&gt;: This divides the result set into partitions and the window functions work independently within each partition.&lt;/p&gt;

&lt;p&gt;For example lets get the Average of the sale_amount and partition by quantity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;avg_sale_amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query calculates the average for ever quantity as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| sale_id | client_id | product_name | quantity | sale_amount | total_quantity |
| ------- | --------- | ------------ | -------- | ----------- | -------------- |
| 4       | 4         | Monitor      | 1        | 35,000      | 35,000         |
| 2       | 2         | Phone        | 2        | 25,000      | 13,000         |
| 6       | 6         | Keyboard     | 2        | 1,000       | 13,000         |
| 1       | 1         | Laptop       | 3        | 75,000      | 80,000         |
| 7       | [NULL]    | Laptop       | 3        | 85,000      | 80,000         |
| 5       | 5         | Printer      | 7        | 35,000      | 35,000         |
| 3       | 3         | Tablet       | 10       | 25,000      | 25,000         |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;u&gt;SUBQUERIES (Nested queries)&lt;/u&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A Subquery is a SQL query written inside another query (a query within a query).&lt;br&gt;
Subqueries allow you to perform an operation that depends on the result of another query.&lt;br&gt;
We mainly use subqueries in order to simplify complex logic, to calculate intermediate results and to filter data dynamically.&lt;/p&gt;

&lt;p&gt;Subqueries can appear in the:&lt;/p&gt;

&lt;p&gt;a)&lt;u&gt;&lt;strong&gt;The SELECT clause&lt;/strong&gt;:&lt;/u&gt; These subqueries add an extra computed column to the result set. Each subquery executes once for every row of the outer query.&lt;br&gt;
Here is an example of a query in the SELECT clause;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="p"&gt;,(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_quantity&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| client_id | client_name   | city         | total_quantity |
| --------- | ------------- | ------------ | -------------- |
| 1         | Alice Johnson | New York     | 3              |
| 2         | Bob Smith     | Los Angeles  | 2              |
| 3         | Charlie Brown | Chicago      | 10             |
| 4         | Diana Prince  | Houston      | 1              |
| 5         | Ethan Hunt    | Phoenix      | 7              |
| 6         | Fiona Clark   | Philadelphia | 2              |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b)&lt;u&gt;&lt;strong&gt;The FROM clause&lt;/strong&gt;&lt;/u&gt;: These subqueries create a temporary or derived table. The outer table can then select or filter data from it.&lt;/p&gt;

&lt;p&gt;Below is an example of a subquery in the FROM clause;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;25000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| product_name | quantity | total_sales |
| ------------ | -------- | ----------- |
| Monitor      | 1        | 35,000      |
| Printer      | 7        | 35,000      |
| Laptop       | 3        | 160,000     |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c)&lt;strong&gt;&lt;u&gt;The WHERE clause&lt;/u&gt;&lt;/strong&gt;: These allow the outer query to filter results based on another query’s output.&lt;/p&gt;

&lt;p&gt;Here is an example of a subquery in the WHERE clause;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;client_id&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;sale_amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;25000&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| client_name   | city     |
| ------------- | -------- |
| Alice Johnson | New York |
| Diana Prince  | Houston  |
| Ethan Hunt    | Phoenix  |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Subqueries can either be Correlated subqueries or Non-correlated queries.&lt;br&gt;
&lt;strong&gt;Correlated subqueries&lt;/strong&gt;: These subqueries depend on the outer query. They are evaluated once per row of the outer query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-Correlated subqueries&lt;/strong&gt;: These subqueries do not depend on the outer query. They can be executed on their own.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;u&gt;COMMON TABLE EXPRESSIONS (CTEs)&lt;/u&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A CTE in SQL is basically creating a temporary table or result set and then querying that temporary table. The temporary table created only exists during the execution of a single SQL query.&lt;br&gt;
A CTE helps make your SQL query easier to read and organize especially when your query becomes long or has multiple subqueries.&lt;br&gt;
The Syntax of a CTE is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;cte_name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="c1"&gt;--SQL query that defines the temporary result&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;cte_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us now explore different ways to write CTEs:&lt;/p&gt;

&lt;p&gt;a)&lt;strong&gt;Basic CTEs&lt;/strong&gt;: These are direct and straight forward CTEs.&lt;br&gt;
For example, let us create a CTE sales_summary with columns product_name, quantity and total_sale_amount. Then we query this CTE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;sales_summary&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
 &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_summary&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query, we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| product_name | quantity | total_amount|
| ------------ | -------- | -------     |
| Monitor      | 1        | 35,000      |
| Printer      | 7        | 35,000      |
| Keyboard     | 2        | 1,000       |
| Tablet       | 10       | 25,000      |
| Laptop       | 3        | 160,000     |
| Phone        | 2        | 25,000      |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b)&lt;strong&gt;CTEs with Joins&lt;/strong&gt;: This is where Joins are incorporated into the CTEs.&lt;/p&gt;

&lt;p&gt;Here is an example of a sql query of a CTE with a join.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;client_purchases&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_quantity&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
        &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
 &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;client_purchases&lt;/span&gt;
 &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;total_quantity&lt;/span&gt; &lt;span class="k"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| client_id | client_name   | product_name | total_quantity |
| --------- | ------------- | ------------ | -------------- |
| 3         | Charlie Brown | Tablet       | 10             |
| 5         | Ethan Hunt    | Printer      | 7              |
| 1         | Alice Johnson | Laptop       | 3              |
| 6         | Fiona Clark   | Keyboard     | 2              |
| 2         | Bob Smith     | Phone        | 2              |
| 4         | Diana Prince  | Monitor      | 1              |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c)&lt;strong&gt;Multiple CTEs in one query&lt;/strong&gt;: This involves defining more than one CTE separated by commas.&lt;/p&gt;

&lt;p&gt;Here is a sql query with multiple CTEs;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;client_purchases&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;
    &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;join&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
        &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;
    &lt;span class="k"&gt;group&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="n"&gt;total_sales&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sale_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;total_sale_amount&lt;/span&gt;
    &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="k"&gt;group&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;cp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total_sale_amount&lt;/span&gt;
 &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;client_purchases&lt;/span&gt; &lt;span class="n"&gt;cp&lt;/span&gt;
 &lt;span class="k"&gt;join&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;
    &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;cp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query, we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| client_id | client_name   | product_name | total_sale_amount |
| --------- | ------------- | ------------ | ----------------- |
| 1         | Alice Johnson | Laptop       | 75,000            |
| 4         | Diana Prince  | Monitor      | 35,000            |
| 5         | Ethan Hunt    | Printer      | 35,000            |
| 2         | Bob Smith     | Phone        | 25,000            |
| 3         | Charlie Brown | Tablet       | 25,000            |
| 6         | Fiona Clark   | Keyboard     | 1,000             |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;d)&lt;strong&gt;Recursive CTEs&lt;/strong&gt;: used when you need to deal with hierarchial data such as managers and employees reporting chains.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     **&amp;lt;u&amp;gt;STORED PROCEDURES&amp;lt;/u&amp;gt;**
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A stored procedure is a named block of sql logic stored in a database and can be executed by calling.&lt;br&gt;
Stored procedures are mainly used to automate repetitive tasks, for validation and to ensure consistency.&lt;/p&gt;

&lt;p&gt;The syntax for Stored procedures is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="k"&gt;REPLACE&lt;/span&gt; &lt;span class="k"&gt;PROCEDURE&lt;/span&gt; &lt;span class="n"&gt;procedure_name&lt;/span&gt; 
&lt;span class="k"&gt;LANGUAGE&lt;/span&gt; &lt;span class="n"&gt;plpgsql&lt;/span&gt; 
&lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt; 
&lt;span class="k"&gt;BEGIN&lt;/span&gt; 
   &lt;span class="c1"&gt;-- SQL statements &lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of the stored procedure syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CREATE → creates the procedure &lt;/li&gt;
&lt;li&gt;OR REPLACE PROCEDURE → updates the procedure if it already exists&lt;/li&gt;
&lt;li&gt;procedure_name → name of your procedure
&lt;/li&gt;
&lt;li&gt;LANGUAGE plpgsql(procedure language for postgresql) → enables procedural features
&lt;/li&gt;
&lt;li&gt;AS $$ ... $$ → defines the body of the procedure &lt;/li&gt;
&lt;li&gt;BEGIN ... start of procedure logic&lt;/li&gt;
&lt;li&gt;END; → start/end of procedure logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After creating the procedure, you can call it using the syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CALL&lt;/span&gt; &lt;span class="n"&gt;procedure_name&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us use our clients table below to demonstrate on stored procedures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clients table
| # | client_id | client_name   | city         |
| - | --------- | ------------- | ------------ |
| 1 | 1         | Alice Johnson | New York     |
| 2 | 2         | Bob Smith     | Los Angeles  |
| 3 | 3         | Charlie Brown | Chicago      |
| 4 | 4         | Diana Prince  | Houston      |
| 5 | 5         | Ethan Hunt    | Phoenix      |
| 6 | 6         | Fiona Clark   | Philadelphia |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example let us create a stored procedure to add clients to our clients table using the syntax below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="k"&gt;REPLACE&lt;/span&gt; &lt;span class="k"&gt;PROCEDURE&lt;/span&gt; &lt;span class="n"&gt;add_clients&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="n"&gt;c_client_name&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;c_city&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;LANGUAGE&lt;/span&gt; &lt;span class="n"&gt;plpgsql&lt;/span&gt;
&lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt; 
    &lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;VALUES&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c_client_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c_city&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query above creates a stored procedure named &lt;u&gt;add_clients&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;To be able to call this stored procedure 'add_clients', we use the query below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CALL&lt;/span&gt; &lt;span class="n"&gt;add_clients&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Sylvia Otiende'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Liverpool'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This adds another client Sylvia Otiende in Liverpool to our clients list   as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| client_id | client_name    | city         |
| --------- | -------------- | ------------ |
| 1         | Alice Johnson  | New York     |
| 2         | Bob Smith      | Los Angeles  |
| 3         | Charlie Brown  | Chicago      |
| 4         | Diana Prince   | Houston      |
| 5         | Ethan Hunt     | Phoenix      |
| 6         | Fiona Clark    | Philadelphia |
| 7         | Sylvia Otiende | Liverpool    |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us update our clients table and update the city of client_id 2 (Bob Smith) to Nairobi. &lt;br&gt;
To create the update_clients procedure, we use the syntax below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="k"&gt;REPLACE&lt;/span&gt; &lt;span class="k"&gt;PROCEDURE&lt;/span&gt; &lt;span class="n"&gt;update_clients&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="n"&gt;c_client_id&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;c_city&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;LANGUAGE&lt;/span&gt; &lt;span class="n"&gt;plpgsql&lt;/span&gt;
&lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt;
    &lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;clients&lt;/span&gt;
    &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c_city&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;client_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c_client_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To call and update client_id 2 city to Nairobi, we use the query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CALL&lt;/span&gt; &lt;span class="n"&gt;update_clients&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Nairobi'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From calling , we get client_id 2 city updated from Los Angeles to Nairobi.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| client_id | client_name    | city         |
| --------- | -------------- | ------------ |
| 1         | Alice Johnson  | New York     |
| 3         | Charlie Brown  | Chicago      |
| 4         | Diana Prince   | Houston      |
| 5         | Ethan Hunt     | Phoenix      |
| 6         | Fiona Clark    | Philadelphia |
| 7         | Sylvia Otiende | Liverpool    |
| 2         | Bob Smith      | Nairobi      |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use stored procedures to;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Insert data into a table&lt;/li&gt;
&lt;li&gt;update data in a table&lt;/li&gt;
&lt;li&gt;Delete data&lt;/li&gt;
&lt;li&gt;For validation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stored procedures are mainly used in;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Banking to record transactions safely &lt;/li&gt;
&lt;li&gt;E-commerce to create orders, update stock, apply discounts &lt;/li&gt;
&lt;li&gt;HR to update staff records, compute payroll actions &lt;/li&gt;
&lt;li&gt;Education to enroll students, assign classes, update results&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In conclusion, advanced SQL techniques play a critical role in transforming raw data into meaningful insights.&lt;br&gt;
By mastering concepts such as joins, window functions, CTEs, subqueries and stored procedures, data analysts are able to handle complex datasets efficiently while maintaining accuracy and clarity. &lt;br&gt;
As organizations continue to rely on data for strategic growth, the ability to apply advanced SQL effectively remains an essential skill for every data analyst aiming to deliver impactful and data-driven solutions.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>datascience</category>
    </item>
    <item>
      <title>EXPLORING SQL JOINS AND WINDOWS</title>
      <dc:creator>Beverline Otiende</dc:creator>
      <pubDate>Tue, 03 Mar 2026 09:13:51 +0000</pubDate>
      <link>https://forem.com/beverline_otiende_6d3045c/exploring-sql-joins-and-windows-41g7</link>
      <guid>https://forem.com/beverline_otiende_6d3045c/exploring-sql-joins-and-windows-41g7</guid>
      <description>&lt;p&gt;In real world analytics, data rarely exists in isolation, rather it is usually stored in separate but related tables. Extracting meaningful insights from these related tables usually require more advanced SQL concepts like;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Joins: which allow you to combine data from multiple tables.&lt;/li&gt;
&lt;li&gt;Window functions: allow you to perform calculations across rows without collapsing your dataset.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mastering these tools transforms SQL from a querying language into a powerful analytical engine. Together they unlock powerful analysis.&lt;/p&gt;

&lt;p&gt;In this article we explore more about JOINS and WINDOWS and how we can use them in our analysis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;SQL JOINS&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
A SQL join combines rows from two or more tables based on a related column. Think of it like merging two Excel sheets sing a common column.&lt;/p&gt;

&lt;p&gt;We use joins when;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have a Normalized Database&lt;/li&gt;
&lt;li&gt;Information is split across multiple tables&lt;/li&gt;
&lt;li&gt;You need enriched reporting datasets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Types of Joins&lt;/strong&gt;&lt;br&gt;
Lets use these two tables to understand more about the types of joins. &lt;/p&gt;

&lt;p&gt;The first table is the employees table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;employees table
| Employee ID | Name    | Department ID | Manager ID | Salary |
| ----------- | ------- | ------------- | ---------- | ------ |
| 1           | Alice   | 1             | NULL       | 50,000 |
| 2           | Bob     | 2             | 1          | 45,000 |
| 3           | Charlie | 1             | 1          | 47,000 |
| 4           | Diana   | 3             | NULL       | 60,000 |
| 5           | Eve     | NULL          | NULL       | 40,000 |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is the second table, departments table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; departments table
+----+---------------+-----------------+
| #  | department_id | department_name |
+----+---------------+-----------------+
| 1  | 1             | Engineering     |
| 2  | 2             | Sales           |
| 3  | 3             | Marketing       |
| 4  | 4             | Finance         |
+----+---------------+-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1.&lt;strong&gt;&lt;em&gt;Inner Join&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
An Inner Join in SQL returns only the rows that have matching values in all the tables involved in the join, excluding any non-matching data.&lt;/p&gt;

&lt;p&gt;From our tables employee table and departments table with the common column department_id, If you want to find the rows with matching values on both the tables you do an Inner Join using the SQL query below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
INNER JOIN departments 
ON employees.department_id = departments.department_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of this Inner Join query is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+---------+-----------------+
| #  | name    | department_name |
+----+---------+-----------------+
| 1  | Alice   | Engineering     |
| 2  | Bob     | Sales           |
| 3  | Charlie | Engineering     |
| 4  | Diana   | Marketing       |
+----+---------+-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.&lt;em&gt;&lt;strong&gt;Left Join(Left Outer Join)&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
A Left Join returns all records from the left table and the matched records from the right table. If no match exists Null values are returned for the right table's columns. It is essential for retaining all data from the primary table while appending related data.&lt;/p&gt;

&lt;p&gt;From our table 'employees' and 'departments' with a shared column 'department_id', we can do a LEFT JOIN to find  all employees and their respective departments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
LEFT JOIN departments 
ON employees.department_id = departments.department_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of this Inner Join query is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+---------+-----------------+
| #  | name    | department_name |
+----+---------+-----------------+
| 1  | Alice   | Engineering     |
| 2  | Bob     | Sales           |
| 3  | Charlie | Engineering     |
| 4  | Diana   | Marketing       |
| 5  | Eve     | NULL            |
+----+---------+-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;strong&gt;&lt;em&gt;Right Join(Right Outer Join)&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
A Right Join in SQL returns all records from the right table and the matching records from the left table. &lt;/p&gt;

&lt;p&gt;If a row in the right table has no corresponding match in the left table, the columns from the left table will contain Null values in the result set.&lt;/p&gt;

&lt;p&gt;From our table 'Employees' and 'Departments' with a shared column 'department_id', we can do a RIGHT JOIN to find  all departments and their respective employees.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
RIGHT JOIN departments 
ON employees.department_id = departments.department_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Right Join query returns;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+---------+-----------------+
| #  | name    | department_name |
+----+---------+-----------------+
| 1  | Alice   | Engineering     |
| 2  | Bob     | Sales           |
| 3  | Charlie | Engineering     |
| 4  | Diana   | Marketing       |
| 5  | NULL    | Finance         |
+----+---------+-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.&lt;strong&gt;&lt;em&gt;Full  Join (Full Outer Join)&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
A Full Join is a SQL operation that returns all rows from both the left and right tables, combining matching rows and including non-matching rows from either table with Null values for the columns of the table that lacks a match. &lt;/p&gt;

&lt;p&gt;It can be thought of as a combination of a Left Join and a Right Join.&lt;/p&gt;

&lt;p&gt;From our table 'Employees' and 'Departments' with a shared column 'department_id', we can do a FULL JOIN to find  all employees and all the departments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
FULL JOIN departments 
ON employees.department_id = departments.department_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of this full join is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+---------+-----------------+
| #  | name    | department_name |
+----+---------+-----------------+
| 1  | Alice   | Engineering     |
| 2  | Bob     | Sales           |
| 3  | Charlie | Engineering     |
| 4  | Diana   | Marketing       |
| 5  | Eve     | NULL            |
| 6  | NULL    | Finance         |
+----+---------+-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;WINDOW FUNCTIONS&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
SQL window functions perform calculations across a set of related rows (a "window") and return a single value for each original row, without collapsing the rows. They contrast with standard aggregate functions that return a single value for an entire group of rows.&lt;/p&gt;

&lt;p&gt;They are commonly used for tasks like Aggregates, rankings and running totals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Windows syntax&lt;/strong&gt;&lt;br&gt;
OVER() - defines the window&lt;br&gt;
PARTITION BY - splits data into groups&lt;br&gt;
ORER BY - defines calculation order&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Window Functions&lt;/strong&gt;&lt;br&gt;
The two types of Window functions are;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Aggregate Window functions&lt;/li&gt;
&lt;li&gt;2. Ranking Window Functions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us use this Staff table to explore Window functions;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Staff table
+---------+--------+-----+-----------------+---------+
| staff_id| name   | age | department_name | salary  |
+---------+--------+-----+-----------------+---------+
| 1       | Tonny  | 26  | Engineering     | 80,000  |
| 2       | Phenny | 16  | Marketing       | 65,000  |
| 3       | Steve  | 30  | Engineering     | 75,000  |
| 4       | Juliet | 40  | Sales           | 30,000  |
| 5       | Nelly  | 22  | Marketing       | 27,000  |
| 6       | Joshua | 20  | Finance         | 55,000  |
+---------+--------+-----+-----------------+---------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;em&gt;&lt;strong&gt;Aggregate Window Functions&lt;/strong&gt;&lt;/em&gt;&lt;/u&gt;&lt;br&gt;
These calculate aggregates over a window of rows while retaining the individual rows.&lt;/p&gt;

&lt;p&gt;They include;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SUM()&lt;/strong&gt; - Adds together numbers within a window.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets find the Sum of the Salaries from the Staff table. We use the query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, age, department_name, salary,
SUM(salary) over (partition by Department_name) as Sum_of_Salary
FROM Staff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query, we get the output;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+-----+-----------------+---------+---------------+
| #  | name   | age | department_name | salary  | sum_of_salary |
+----+--------+-----+-----------------+---------+---------------+
| 1  | Tonny  | 26  | Engineering     | 80,000  | 155,000       |
| 2  | Steve  | 30  | Engineering     | 75,000  | 155,000       |
| 3  | Joshua | 20  | Finance         | 55,000  | 55,000        |
| 4  | Phenny | 16  | Marketing       | 65,000  | 92,000        |
| 5  | Nelly  | 22  | Marketing       | 27,000  | 92,000        |
| 6  | Juliet | 40  | Sales           | 30,000  | 30,000        |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AVG()&lt;/strong&gt; - calculates the average within a window&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eg Finding the average from our Staff table, we use the SQL query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, age, department_name, salary,
AVG(salary) over (partition by Department_name) as AVG_Salary
FROM Staff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this query we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+-----+-----------------+---------+-----------+
| #  | name   | age | department_name | salary  | avg_salary|
+----+--------+-----+-----------------+---------+-----------+
| 1  | Tonny  | 26  | Engineering     | 80,000  | 77,500    |
| 2  | Steve  | 30  | Engineering     | 75,000  | 77,500    |
| 3  | Joshua | 20  | Finance         | 55,000  | 55,000    |
| 4  | Phenny | 16  | Marketing       | 65,000  | 46,000    |
| 5  | Nelly  | 22  | Marketing       | 27,000  | 46,000    |
| 6  | Juliet | 40  | Sales           | 30,000  | 30,000    |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;MAX() - returns maximum value in the window&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example lets find the Maximum salary in the Staff table and partition by department_name. we use the sql query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, age, department_name, salary,
MAX(salary) over (partition by Department_name) as max_Salary
FROM Staff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We get the output as;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+-----+-----------------+---------+------------+
| #  | name   | age | department_name | salary  | max_salary |
+----+--------+-----+-----------------+---------+------------+
| 1  | Tonny  | 26  | Engineering     | 80,000  | 80,000     |
| 2  | Steve  | 30  | Engineering     | 75,000  | 80,000     |
| 3  | Joshua | 20  | Finance         | 55,000  | 55,000     |
| 4  | Phenny | 16  | Marketing       | 65,000  | 65,000     |
| 5  | Nelly  | 22  | Marketing       | 27,000  | 65,000     |
| 6  | Juliet | 40  | Sales           | 30,000  | 30,000     |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;MIN() - returns minimum value in the window.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example lets find the Minimum salary in the Staff table and partition by department_name. we use the SQL query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, age, department_name, salary,
MIN(salary) over (partition by Department_name) as min_Salary
FROM Staff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the query we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+-----+-----------------+---------+------------+
| #  | name   | age | department_name | salary  | min_salary |
+----+--------+-----+-----------------+---------+------------+
| 1  | Tonny  | 26  | Engineering     | 80,000  | 75,000     |
| 2  | Steve  | 30  | Engineering     | 75,000  | 75,000     |
| 3  | Joshua | 20  | Finance         | 55,000  | 55,000     |
| 4  | Phenny | 16  | Marketing       | 65,000  | 27,000     |
| 5  | Nelly  | 22  | Marketing       | 27,000  | 27,000     |
| 6  | Juliet | 40  | Sales           | 30,000  | 30,000     |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;COUNT() - counts the rows within a window.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example lets find the count of names in the Staff table and partition by department_name. we use the SQL query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, age, department_name, salary,
COUNT(salary) over (partition by Department_name) as count_of_names
FROM Staff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the query we get;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+-----+-----------------+---------+----------------+
| #  | name   | age | department_name | salary  | count_of_names |
+----+--------+-----+-----------------+---------+----------------+
| 1  | Tonny  | 26  | Engineering     | 80,000  | 2              |
| 2  | Steve  | 30  | Engineering     | 75,000  | 2              |
| 3  | Joshua | 20  | Finance         | 55,000  | 1              |
| 4  | Phenny | 16  | Marketing       | 65,000  | 2              |
| 5  | Nelly  | 22  | Marketing       | 27,000  | 2              |
| 6  | Juliet | 40  | Sales           | 30,000  | 1              |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt; &lt;em&gt;&lt;strong&gt;Ranking Window Functions&lt;/strong&gt;&lt;/em&gt;&lt;/u&gt;&lt;br&gt;
These return rankings of rows within a partition based on a specific criteria.&lt;/p&gt;

&lt;p&gt;They include;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RANK()&lt;/strong&gt; - Assigns ranks to rows(it skips ranks for duplicates) within a   window.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets use RANK() to rank our staff salaries in Descending order and partition by department_name. We use the query;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, age, department_name, salary,
RANK() over (partition by Department_name order by Salary DESC) as salary_rank
FROM Staff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The query returns;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+-----+-----------------+---------+------------+
| #  | name   | age | department_name | salary  | salary_rank|
+----+--------+-----+-----------------+---------+------------+
| 1  | Tonny  | 26  | Engineering     | 80,000  | 1          |
| 2  | Steve  | 30  | Engineering     | 75,000  | 2          |
| 3  | Joshua | 20  | Finance         | 55,000  | 1          |
| 4  | Phenny | 16  | Marketing       | 65,000  | 1          |
| 5  | Nelly  | 22  | Marketing       | 27,000  | 2          |
| 6  | Juliet | 40  | Sales           | 30,000  | 1          |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ROW_NUMBER()&lt;/strong&gt; - assigns unique numbers to rows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets get the row numbers from our staff table based on Salary DESC and partition by department_name;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, age, department_name, salary,
ROW_NUMBER() OVER (PARTITION BY Department_name order by Salary DESC) as staff_row_number
FROM Staff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query returns;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+-----+-----------------+---------+----------------+
| #  | name   | age | department_name | salary  | staff_row_number|
+----+--------+-----+-----------------+---------+----------------+
| 1  | Tonny  | 26  | Engineering     | 80,000  | 1              |
| 2  | Steve  | 30  | Engineering     | 75,000  | 2              |
| 3  | Joshua | 20  | Finance         | 55,000  | 1              |
| 4  | Phenny | 16  | Marketing       | 65,000  | 1              |
| 5  | Nelly  | 22  | Marketing       | 27,000  | 2              |
| 6  | Juliet | 40  | Sales           | 30,000  | 1              |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DENSE_RANK()&lt;/strong&gt;- assigns ranks to rows without skipping rank numbers for duplicates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PERCENT_RANK()&lt;/strong&gt; - shows the relative rank of a row as a percentage between 0 and 1.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When working with Window functions, you have to ;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Partition carefully because without Partition by the whole table is treated as one group.&lt;/li&gt;
&lt;li&gt;Order by where necessary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Conclusion, SQL Joins and Windows are fundamental to effective data analysis.&lt;/p&gt;

&lt;p&gt;Joins allow us to combine related tables into meaningful datasets while window functions enable advanced calculations such as rankings and aggregate operations while keeping the rows intact.&lt;/p&gt;

&lt;p&gt;Together, these tools transform SQL from a simple querying language into  a powerful analytical resource.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How Analysts Translate Messy Data, DAX and Dashboards into Action using PowerBI</title>
      <dc:creator>Beverline Otiende</dc:creator>
      <pubDate>Mon, 09 Feb 2026 07:23:47 +0000</pubDate>
      <link>https://forem.com/beverline_otiende_6d3045c/how-analysts-translate-messy-data-dax-and-dashboards-into-action-using-powerbi-211e</link>
      <guid>https://forem.com/beverline_otiende_6d3045c/how-analysts-translate-messy-data-dax-and-dashboards-into-action-using-powerbi-211e</guid>
      <description>&lt;p&gt;As an analyst, you will always begin your analysis with raw data that is often messy, inconsistent, incomplete and scattered across multiple systems. To be able to create value from this raw data, you will have to first clean, model, standardize and finally transform your raw data into insights that guide strategic data driven decision making.&lt;br&gt;
PowerBI is one of the most powerful business intelligence tools analysts use to bridge the gap between messy data and actionable business intelligence.&lt;/p&gt;

&lt;p&gt;This article explores how we can use PowerBI to do data cleaning, data modelling, DAX (Data Analysis Expressions) and in creating dashboard designs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Cleaning and Transforming Messy Data in PowerBI&lt;/strong&gt;&lt;br&gt;
Data cleaning is the process of identifying and correcting errors, inconsistencies and inaccuracies in data sets.&lt;br&gt;
Data cleaning is very crucial because it enables us to work with clean, structured and relevant data in our analysis unlike using uncleaned data that is poor quality data which translates to incorrect analysis and decisions.&lt;br&gt;
Power Query in PowerBI allows analysts to clean and transform raw data through;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Removing duplicates&lt;/li&gt;
&lt;li&gt;Handling missing values and errors&lt;/li&gt;
&lt;li&gt;Fixing datatypes&lt;/li&gt;
&lt;li&gt;Standardizing formats&lt;/li&gt;
&lt;li&gt;Splitting or merging columns&lt;/li&gt;
&lt;li&gt;Filtering irrelevant records&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65udl2qx8mpzzrzifpe6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65udl2qx8mpzzrzifpe6.png" alt="Power query features" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structuring data with proper modelling&lt;/strong&gt;&lt;br&gt;
After data cleaning, it is important to build relationships between tables using proper data modelling techniques.&lt;br&gt;
Data modelling is basically setting up tables, relationships, calculations and access for analysis scenarios&lt;br&gt;
Good data modelling in PowerBI involves incorporating a Star Schema which improves performance, the accuracy of calculations, flexibility of reporting and scalability for future analysis.&lt;br&gt;
Proper Modelling often involves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating fact tables&lt;/li&gt;
&lt;li&gt;Creating Dimension tables&lt;/li&gt;
&lt;li&gt;Designing a Star Schema&lt;/li&gt;
&lt;li&gt;Defining relationships between the tables.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Turning Data into Insights with DAX (Data Analysis Expression)&lt;/strong&gt;&lt;br&gt;
DAX is the formula language used in PowerBI to create custom calculations. We use DAX to transform structured data into meaningful business insights.&lt;br&gt;
DAX enables us to calculate New measures and New columns to compute key metrics such as Total Revenue, Profit margins, growth rates among others.&lt;br&gt;
For example, DAX allow you to create a New Measure for Total Revenue as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Total Revenue = SUM(Kenya_Crops_Cleaned_Final[Revenue (KES)])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also create a New Column as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Expected Selling Price = Kenya_Crops_Cleaned_Final[Market Price (KES/Kg)]*Kenya_Crops_Cleaned_Final[Yield (Kg)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use New Measure if you expect a single output while we use New Column if the expected outpu is multiple rows corresponding to the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Designing Dashboards in PowerBI&lt;/strong&gt;&lt;br&gt;
A dashboard is not just a collection of charts but a clear visual representation of our analysis that supports effective decision making.&lt;br&gt;
An effective PowerBI dashboard must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Highlight Key Performance Indicators(KPIs)&lt;/li&gt;
&lt;li&gt;Use appropriate graphs to draw attention to critical metrics&lt;/li&gt;
&lt;li&gt;Present insights clearly and concisely&lt;/li&gt;
&lt;li&gt;Enable filtering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of a PowerBI dashboard with KPIs, Slicers and Charts&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3rtiqj1gf40sr1vi560r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3rtiqj1gf40sr1vi560r.png" alt="A PowerBI dashboard" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
PowerBI is more than just a visualization tool. It is a platform that enables us as analysts to transform messy data into reliable insights that drive real business decisions.&lt;br&gt;
We use Power Query to clean the data, Data modelling to organize the data , DAX enables us perform dynamic calculations and the dashboard for visualizations and insights.&lt;br&gt;
We are able to use PowerBI to find out what happened, why it happened and what will happen through data cleaning, data modelling, DAX calculations and interactive dashboards.&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>data</category>
      <category>microsoft</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Schemas and Data Modelling in PowerBI</title>
      <dc:creator>Beverline Otiende</dc:creator>
      <pubDate>Mon, 02 Feb 2026 10:29:18 +0000</pubDate>
      <link>https://forem.com/beverline_otiende_6d3045c/schemas-and-data-modelling-in-powerbi-3nad</link>
      <guid>https://forem.com/beverline_otiende_6d3045c/schemas-and-data-modelling-in-powerbi-3nad</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction to Data Modelling in PowerBI&lt;/strong&gt;&lt;br&gt;
Data Modelling is the process of structuring raw data into a logical format by setting up tables, connecting multiple data sources using relationships and calculations in order to make analysis fast, accurate and easy to understand.&lt;br&gt;
Data modelling in PowerBI greatly affects the quality of insights you get from your data.&lt;br&gt;
A good data model must define:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How tables are organized&lt;/li&gt;
&lt;li&gt;The relationship between the tables&lt;/li&gt;
&lt;li&gt;The Calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Schema in Data Modelling&lt;/strong&gt;&lt;br&gt;
A Schema is the overall structure of how data tables are arranged and connected in a model.&lt;br&gt;
In PowerBI, Schemas mainly describe how fact tables connect to dimension tables and the flow of filters between tables.&lt;br&gt;
A &lt;u&gt;fact table&lt;/u&gt; is the center table of a data model and contains measurable, quantitative data used for analysis&lt;br&gt;
A&lt;u&gt; dimension table&lt;/u&gt; is a table that explains a certain aspect or dimension in the fact table. It provides a descriptive context for facts&lt;br&gt;
The two most common Schemas used are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Star Schema&lt;/li&gt;
&lt;li&gt;Snowflakes Schema&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;1.&lt;u&gt; Star Schema&lt;/u&gt;&lt;br&gt;
A Star Schema is a data model where you have one central fact table and multiple dimension tables all connected.&lt;br&gt;
It looks like a Star when visualized.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Structure of Star Schema&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A fact table in the middle&lt;/li&gt;
&lt;li&gt;Dimension tables around it&lt;/li&gt;
&lt;li&gt;No relationship between dimension tables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwnfjrjopiff18vd4hxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwnfjrjopiff18vd4hxc.png" alt="Star Schema Visual representation" width="800" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdohp4ds215nvf9bx9ep.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdohp4ds215nvf9bx9ep.png" alt="Star Schema representation" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Advantages of a Star Schema include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They are simple and intuitive&lt;/li&gt;
&lt;li&gt;Best performance in PowerBI&lt;/li&gt;
&lt;li&gt;They have fewer relationships&lt;/li&gt;
&lt;li&gt;Easier DAX calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Star Schema is the recommended modelling approach in PowerBI.&lt;/p&gt;

&lt;p&gt;2.&lt;u&gt;Snowflake Schema&lt;/u&gt;&lt;br&gt;
A snowflake Schema is  a more complex version of a star schema where dimensions are normalized and dimensions connect to other dimensions.&lt;br&gt;
They are more common in databases but not ideal for PowerBI unless unavoidable.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Structure of a Snowflake Schema&lt;/em&gt;&lt;br&gt;
Has a fact table that connects to a dimension table&lt;br&gt;
That dimension connects to another dimension&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1jif3cak66y0s4mxspm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1jif3cak66y0s4mxspm.png" alt="Snowflake Schema" width="800" height="537"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fla79nuuvvsvmii9bap8m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fla79nuuvvsvmii9bap8m.png" alt="Snowflake Schema representation" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Advantages of a Star schema include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There is reduced data redundancy&lt;/li&gt;
&lt;li&gt;Smaller dimension tables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disadvantages of Snowflakes schemas&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They are harder to understand&lt;/li&gt;
&lt;li&gt;Slower performance&lt;/li&gt;
&lt;li&gt;More complex DAX&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Importance of Good Modelling in PowerBI&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It improves overall performance: Good modelling ensures we have fewer tables and relationships which translates to faster reports. Star schema reduces query complexity and ensures efficient memory usage.&lt;/li&gt;
&lt;li&gt;Ensures accuracy in Calculations and reporting &lt;/li&gt;
&lt;li&gt;Simplicity and usability: Good modelling simplifies DAX calculations and ensures easier debugging and maintenance.&lt;/li&gt;
&lt;li&gt;Scalability: Good modelling makes it easy to add new dimensions and easier to create new measures. &lt;/li&gt;
&lt;li&gt;Reduces Data redundancy and storage size&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, effective modelling is the foundation of successful PowerBI reporting. Data modelling comes first since good visuals cannot fix a bad data model.&lt;br&gt;
Using a Star Schema, clearly separating the fact and dimension tables and defining proper relationships ensures effective modelling and thus accurate calculations and reliable reports.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Evaluating Microsoft Excel as a Data Analytics tool in Modern Business Decision Making</title>
      <dc:creator>Beverline Otiende</dc:creator>
      <pubDate>Sun, 25 Jan 2026 14:35:18 +0000</pubDate>
      <link>https://forem.com/beverline_otiende_6d3045c/evaluating-microsoft-excel-as-a-data-analytics-tool-in-modern-business-decision-making-37hd</link>
      <guid>https://forem.com/beverline_otiende_6d3045c/evaluating-microsoft-excel-as-a-data-analytics-tool-in-modern-business-decision-making-37hd</guid>
      <description>&lt;p&gt;Microsoft Excel remains one of the most commonly used tools for Data Analytics in businesses and organizations. This is mainly because it is very easy to use, it is easily accessible and powerful enough to handle many data analysis tasks.&lt;br&gt;
This article explores ways in what Excel is and how it is used in data analysis. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WHAT IS MICROSOFT EXCEL&lt;/strong&gt;&lt;br&gt;
Excel is a spreadsheet program that can be used to organize data, to perform calculation, clean data, create visualizations and analyze data.&lt;br&gt;
Data Analytics on the other hand involves examining raw data in order to identify patterns and draw data-driven insights that support decision making in organizations and businesses.&lt;br&gt;
Excel as a tool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXCEL TEXT FUNCTIONS&lt;/strong&gt;&lt;br&gt;
Text Functions in Excel are used as part of data cleaning to get a section of data or to extract relevant information from text fields.&lt;br&gt;
They include;&lt;br&gt;
&lt;em&gt;&lt;u&gt;LEFT Function&lt;/u&gt;&lt;/em&gt;: extracts text from the left side of a cell. Its syntax is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=LEFT(text, number_of_characters_to_extract)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;u&gt;RIGHT Function&lt;/u&gt;&lt;/em&gt;: extracts text from the right side of a cell. Syntax is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=RIGHT(text, number_of_characters_to_extract)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;u&gt;MID Function&lt;/u&gt;&lt;/em&gt;: extracts text from the middle of a cell. Syntax is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=MID(text, start_position, number_of_characters)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;u&gt;LEN Function&lt;/u&gt;&lt;/em&gt;: counts the number of characters in a text. syntax is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=LEN(text)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;u&gt;TRIM Function&lt;/u&gt;&lt;/em&gt;: removes extra spaces from a text. Syntax is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=TRIM(text)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;u&gt;CONCATENATE Function&lt;/u&gt;&lt;/em&gt;: joins texts from different cells. Syntax is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=CONCATENATE(text1, " ", text2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;DATA VALIDATION&lt;/strong&gt;&lt;br&gt;
This is done to restrict what is entered in a cell during data entry to avoid errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REMOVING BLANKS&lt;/strong&gt;&lt;br&gt;
Removing blanks is a common aspect in data cleaning.&lt;br&gt;
To remove blanks;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Choose column you want to remove blanks from&lt;/li&gt;
&lt;li&gt;Go to Home tab and then to Find and Select&lt;/li&gt;
&lt;li&gt;Go to Special then Remove Blanks.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;PERFORMING BASIC ARITHMETIC OPERATIONS IN EXCEL&lt;/strong&gt;&lt;br&gt;
With Excel you can do Basic Addition, Subtraction, Division, Multiplication, Power and many more.&lt;br&gt;
All you have to do is put "=" before you write what you want to add or Multiply or Divide;&lt;br&gt;
e.g &lt;br&gt;
= 2+2 gives you 4 for Addition&lt;br&gt;
= 10/2 gives 5 for Division&lt;br&gt;
= 5* 3 gives 15 for Multiplication&lt;br&gt;
=17-9 gives 8 for Subtraction&lt;br&gt;
= 2^3 gives 8 for Powers&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGGREGATE FUNCTIONS&lt;/strong&gt;&lt;br&gt;
We have special functions we use when performing arithmetic operations like Sum, difference, Average just to mention but a few.&lt;br&gt;
Assume you have a column of data from range E2 TO E16 you want to calculate different parameters.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;Adding the numbers together&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;/u&gt;    = SUM(E2:E16)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a8bju6eyrf2l6ysxx9t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a8bju6eyrf2l6ysxx9t.png" alt="SUM function" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;Finding the Average&lt;/em&gt;&lt;br&gt;
&lt;/u&gt;   = AVERAGE(E2:E16)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zr2k13rgo77k6cirja7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zr2k13rgo77k6cirja7.png" alt="Average function" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;Finding Maximum Value&lt;/em&gt; &lt;br&gt;
&lt;/u&gt;   =MAX(E2:E16)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcwck7zqjw0945f2x2tc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcwck7zqjw0945f2x2tc.png" alt="Maximum function" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;Finding Minimum value&lt;/em&gt;&lt;br&gt;
&lt;/u&gt;   =MIN(E2:E16)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mcqo5rpx89vmmorlzfh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5mcqo5rpx89vmmorlzfh.png" alt="Minimum Function" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;u&gt;&lt;em&gt;Finding the Count&lt;/em&gt;&lt;br&gt;
&lt;/u&gt;   =COUNT(E2:E16)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhpbxfwx0cz9hgxy7nvui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhpbxfwx0cz9hgxy7nvui.png" alt="Count function" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LOGICAL FUNCTIONS&lt;/strong&gt;&lt;br&gt;
Logical functions in Excel help you make decisions in your data.&lt;br&gt;
They check whether a condition is TRUE or FALSE and then return a result based on your condition.&lt;br&gt;
They include;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;em&gt;IF Function&lt;/em&gt;&lt;/u&gt;: Checks a condition and returns a value if the condition is True and another value if it is False. Its syntax is shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=IF(condition, value_if_true, value_if_false)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;em&gt;AND Function&lt;/em&gt;&lt;/u&gt;: Returns TRUE only if all conditions are met. Its syntax is shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=AND(condition 1, condition 2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;em&gt;OR Function&lt;/em&gt;&lt;/u&gt;: Returns True if at least one of the conditions is True. Its syntax is shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=OR(condition 1, condition 2)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;em&gt;NOT Function&lt;/em&gt;&lt;/u&gt;: It reverses the logical result. Its syntax is shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=NOT(condition)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;PIVOT TABLES&lt;/strong&gt;&lt;br&gt;
A Pivot Table is a powerful Excel tool that helps us summarize, analyze and explore large amounts of data without writing formulas.&lt;br&gt;
To insert a Pivot table;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select your entire table&lt;/li&gt;
&lt;li&gt;Go to the Insert tab and Select Pivot Table(on the extreme left)&lt;/li&gt;
&lt;li&gt;Select New Worksheet then press Okay&lt;/li&gt;
&lt;li&gt;Then drag and drop your columns on the Row, Value and Column section on the Right depending on the summary you want. On the Values section, you can specify if you want Sum, Average, Count or anything else. To do that, you select under the 'Values' section, Select your Value, the Value field settings, select the summary you want eg Sum, count. then press Okay&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhtnechrhag1s40ym2ran.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhtnechrhag1s40ym2ran.png" alt="Inserting Pivot table" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F103qvn71y3w23wxvjilw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F103qvn71y3w23wxvjilw.png" alt="Select New worksheet" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfbprk866stfx60jn3cb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfbprk866stfx60jn3cb.png" alt="Blank Pivot table" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrw4fxnvaxi37qegutu2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrw4fxnvaxi37qegutu2.png" alt="Pivot Table with Rows and Values" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h7z7lhyds00cz0n9az7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h7z7lhyds00cz0n9az7.png" alt="Value field settings" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3wo7j5g5be8zjfryhbe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3wo7j5g5be8zjfryhbe.png" alt="Pivot table with Rows, Columns and Values" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SLICERS&lt;/strong&gt;&lt;br&gt;
Slicers provide Visual Filters for Pivot tables and pivot charts.&lt;br&gt;
To insert a slicer for a Pivot Table;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select anywhere on the Pivot Table&lt;/li&gt;
&lt;li&gt;Go to PivotTable Analyze Tab and Select Slicer&lt;/li&gt;
&lt;li&gt;Select the Slicers you want to have and click Okay. Based on your selection on your slicer, your data values change.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwve0rmtd5hfacnaf5pj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwve0rmtd5hfacnaf5pj.png" alt="Inserting Slicer" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fme72y6pgz7ahcdl2qlat.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fme72y6pgz7ahcdl2qlat.png" alt="Selecting your slicers" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xnoi6j0xra3ck3ab9ij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xnoi6j0xra3ck3ab9ij.png" alt="Slicers" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv8bi3i2g9pw04g3mp5cj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv8bi3i2g9pw04g3mp5cj.png" alt="Filtering with slicers" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PIVOT CHARTS&lt;/strong&gt;&lt;br&gt;
Pivot Charts are used for visualizations and are made from Pivot tables &lt;br&gt;
To insert a Pivot chart;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select anywhere on your Pivot Chart&lt;/li&gt;
&lt;li&gt;Go to the PivotTable Analyze Tab the select Pivot Chart&lt;/li&gt;
&lt;li&gt;Select the chart you want to input either Column chart, Bar chart, Pie Chart among others depending on your data and analysis.&lt;/li&gt;
&lt;li&gt;Modify the chart according to your preferences.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d5982w47dv54jigfxmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d5982w47dv54jigfxmg.png" alt="Inserting pivot chart" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0svlbtzg7k3dnkuugf3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0svlbtzg7k3dnkuugf3.png" alt="Selecting a chart" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptsuvvkv5k4l09os64aj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptsuvvkv5k4l09os64aj.png" alt="A column chart" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9yah89aewkpzqanto7su.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9yah89aewkpzqanto7su.png" alt="Doughnut chart" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Pivot charts show a graphical representation of Pivot tables and you can use them depending on your data and analysis.&lt;br&gt;
Commonly used charts include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;u&gt;Line charts&lt;/u&gt;: To show trends over time&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Column charts&lt;/u&gt;: Compares values across categories using vertical bars.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Bar charts&lt;/u&gt;: Compares values across categories using horizontal bars.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Pie/Doughnut Chats&lt;/u&gt;: Shows proportions of a whole.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Combo charts&lt;/u&gt;: Combines two chart types.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Histogram&lt;/u&gt;: Shows distribution of numeric data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;BUILDING A DASHBOARD&lt;/strong&gt;&lt;br&gt;
An Excel Dashboard is a visual summary of key metrics and trends, usually on one worksheet and is designed for quick understanding by managers and stakeholders.&lt;br&gt;
Key considerations for a Dashboard include;&lt;br&gt;
• One screen only (no scrolling)&lt;br&gt;
• Focus on key KPIs, not raw data&lt;br&gt;
• Consistent colors and fonts&lt;br&gt;
• Clear titles and labels&lt;br&gt;
• Interactive but simple&lt;br&gt;
When building a dashboard, open a new Excel worksheet, then copy and paste the Pivot Charts you would like to have in there plus the slicer. Ensure your Dashboard is neat and organized.&lt;br&gt;
Also use dashboard colors according to the theme of the company you are presenting to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmrvn2pqm5dn433lif9fu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmrvn2pqm5dn433lif9fu.png" alt="Dashboard example" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>data</category>
      <category>microsoft</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A beginners guide to Git: Version control, Tracking changes, Pushing and Pulling Code.</title>
      <dc:creator>Beverline Otiende</dc:creator>
      <pubDate>Sun, 18 Jan 2026 04:13:09 +0000</pubDate>
      <link>https://forem.com/beverline_otiende_6d3045c/a-beginners-guide-to-git-version-control-tracking-changes-pushing-and-pulling-code-44p6</link>
      <guid>https://forem.com/beverline_otiende_6d3045c/a-beginners-guide-to-git-version-control-tracking-changes-pushing-and-pulling-code-44p6</guid>
      <description>&lt;p&gt;If you are serious about Tech, then Git is one of the non-negotiables. You've probably heard about the word Git and Github thrown around by 'Techies' and it may sound intimidating to you as a beginner.&lt;br&gt;
In this article, we are going to breakdown and understand what Git is and how we can use it.&lt;br&gt;
This article aims to explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What version control is&lt;/li&gt;
&lt;li&gt;What git is and how it matters&lt;/li&gt;
&lt;li&gt;How Git tracks changes&lt;/li&gt;
&lt;li&gt;How to push and pull code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Understanding Version control&lt;/strong&gt;&lt;br&gt;
Version control is a system that tracks and records changes made to our code over time in a special database called repository.&lt;br&gt;
A repository in simple terms is a project folder that Git is tracking. &lt;br&gt;
Think of version control as a time machine + a collaboration tool for your code that helps us work together and track changes.&lt;br&gt;
It also helps us know what changes were made to our code and by who, and if you screw something up you can easily revert your project back to an earlier state.&lt;br&gt;
There  are different version control system but Git is the most common one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Git and why it matters&lt;/strong&gt;&lt;br&gt;
Git is the most popular version control system in the world. This is mainly because it is free, open source, super fast and scalable.&lt;br&gt;
The main difference between Git and Github is that Git is a tool installed in your computer and Github is an online platform that stores Git repositories.&lt;br&gt;
To be able to use Git you have to install it in your computer using the link; &lt;a href="https://git-scm.com/download/win" rel="noopener noreferrer"&gt;google&lt;/a&gt; for windows and for mac and Linux install via the official site.&lt;/p&gt;

&lt;p&gt;To check the version of git installed in you computer yo run the code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git runs locally on your computer and;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tracks every change you make to your files&lt;/li&gt;
&lt;li&gt;Knows who made each change and when&lt;/li&gt;
&lt;li&gt;Allows you to save snapshots of your project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;How Git tracks changes&lt;br&gt;
&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
Git generally has three main states for its files;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Working directory: this is where you edit files&lt;/li&gt;
&lt;li&gt;Staging area: this is where you tell Git the changes you want to save&lt;/li&gt;
&lt;li&gt;Repository(History): this is where Git permanently stores snapshots(commits).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A commit is a snapshot of your project at a specific time and&lt;br&gt;
Each commit normally has a;&lt;br&gt;
-Unique ID&lt;br&gt;
-Author&lt;br&gt;
-Date&lt;br&gt;
-Message&lt;br&gt;
The commit history acts as the Git time machine and we can view it using the code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pushing code to GitHub(Git push)&lt;/strong&gt;&lt;br&gt;
Git push means sending your local commits to the remote repository(Github).&lt;br&gt;
To push code to Github, we use the code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -u origin name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you enter this code on your Git, your code appears on Github and is visible to other people.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pulling code from Github(Git pull)&lt;/strong&gt;&lt;br&gt;
This is done to get the latest changes from the remote repository(Github).&lt;br&gt;
The code for pulling code is;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git pull is very important especially when working on multiple machine, collaborating with others and when updating your local copy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Git is essential for your career&lt;/strong&gt;&lt;br&gt;
If you are serious about Tech, then Git is a non-negotiable for your career.&lt;br&gt;
Git mainly helps you to;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Collaborate with teams worldwide&lt;/li&gt;
&lt;li&gt;Work safely without fear&lt;/li&gt;
&lt;li&gt;Show your work to employers&lt;/li&gt;
&lt;li&gt;Contribute to open source projects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When working with Git as a beginner, it is very important to;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always commit often in small chunks&lt;/li&gt;
&lt;li&gt;Be specific and clear with your commit messages&lt;/li&gt;
&lt;li&gt;Always Git pull before starting work&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, Git may feel confusing at first, but it becomes second nature with practice. Just start small, make mistakes, learn and keep going.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>git</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
