Analyzing Sales Data with a Comprehensive SQL Query in Microsoft Fabric Data Warehouse

SQL queries play a crucial role in extracting meaningful insights from large datasets. One such powerful SQL query is designed to analyze sales data comprehensively, offering a detailed breakdown of sales performance by account manager, payment type, and region. This query is not only effective in aggregating data but also provides a clear structure for understanding the distribution of sales across different dimensions. The query is executed in the Microsoft Fabric Data Warehouse.

SELECT 
    a.AccountManager, pt.PaymentType, r.Region, 
    SUM(SalesAmount) as TotalSales, COUNT(*) AS CountofSales
FROM dimAccountManager a
INNER JOIN fTransaction f ON a.AccountManagerID = f.AccountManagerID
INNER JOIN dimPaymentType pt ON f.AccountManagerID = pt.PaymentTypeID
INNER JOIN dimRegion r ON pt.PaymentTypeID = r.RegionID
GROUP BY a.AccountManager, pt.PaymentType, r.Region;

Breakdown of the SQL Query

  • Selection of Columns: a.AccountManager: Represents the account manager from the dimension table dimAccountManager.
  • pt.PaymentType: Represents the payment type from the dimension table dimPaymentType.
  • r.Region: Represents the region from the dimension table dimRegion.
  • SUM(SalesAmount) as TotalSales: Calculates the total sales amount by summing up the SalesAmount column from the fact table fTransaction.
  • COUNT(*) AS CountofSales: Counts the number of sales transactions.

Table Joins

The query employs inner joins to connect the relevant tables. These joins link the account manager, payment type, and region dimensions to the transactional data in the fact table.

  • a.AccountManagerID = f.AccountManagerID: Joins the dimAccountManager and fTransaction tables based on the account manager ID.
  • f.AccountManagerID = pt.PaymentTypeID: Joins the fTransaction and dimPaymentType tables based on the payment type ID.
  • pt.PaymentTypeID = r.RegionID: Joins the dimPaymentType and dimRegion tables based on the region ID.

Grouping and Aggregation

GROUP BY a.AccountManager, pt.PaymentType, r.Region: Groups the data by account manager, payment type, and region. This allows for the aggregation of sales data at a granular level.

The screenshot below shows the query result with 5 rows.

SQL Query


Similar Articles