Aggregate Functions in Fabric Warehouse – SUM, AVG, MAX, MIN, COUNT | Microsoft Fabric Tutorial

Aggregate Functions in Fabric Warehouse – SUM, AVG, MAX, MIN, COUNT

Aggregate Functions in Fabric Warehouse – SUM, AVG, MAX, MIN, COUNT

In this Microsoft Fabric tutorial, you’ll learn how to use T-SQL aggregate functions like SUM(), AVG(), MAX(), MIN(), and COUNT() within a Warehouse. These functions are essential for summarizing and analyzing data efficiently.

📘 What Are Aggregate Functions?

Aggregate functions perform calculations on a set of values and return a single summarized result. They are commonly used in SELECT statements with or without GROUP BY to produce insights.

✅ Step 1: Create a Sales Table

CREATE TABLE dbo.Sales (
    SaleID INT,
    SalesPerson VARCHAR(50),
    Region VARCHAR(50),
    SaleAmount DECIMAL(10, 2),
    SaleDate DATE
);

✅ Step 2: Insert Sample Sales Data

INSERT INTO dbo.Sales (SaleID, SalesPerson, Region, SaleAmount, SaleDate)
VALUES
(1, 'Aamir', 'East', 1500.00, '2024-01-01'),
(2, 'Sara', 'West', 2200.00, '2024-01-02'),
(3, 'John', 'East', 1800.00, '2024-01-03'),
(4, 'Aamir', 'East', 1700.00, '2024-01-04'),
(5, 'Sara', 'West', 2100.00, '2024-01-05'),
(6, 'Mia', 'North', 950.00, '2024-01-06'),
(7, 'Mia', 'North', 1200.00, '2024-01-07'),
(8, 'John', 'East', 1600.00, '2024-01-08'),
(9, 'Aamir', 'East', 1900.00, '2024-01-09'),
(10, 'Sara', 'West', 2500.00, '2024-01-10');

👁️ Step 3: View Raw Sales Data

SELECT * FROM dbo.Sales;

📊 Step 4: Use of Aggregate Queries

4.1: Total Sales Amount

SELECT SUM(SaleAmount) AS TotalSales FROM dbo.Sales;

4.2: Average Sale Amount

SELECT AVG(SaleAmount) AS AverageSale FROM dbo.Sales;

4.3: Highest Sale Amount

SELECT MAX(SaleAmount) AS HighestSale FROM dbo.Sales;

4.4: Lowest and Highest Sale

SELECT MIN(SaleAmount) AS LowestSale, MAX(SaleAmount) AS HighestSale FROM dbo.Sales;

4.5: Total Number of Transactions

SELECT COUNT(*) AS TotalTransactions FROM dbo.Sales;

4.6: Total Sales by SalesPerson

SELECT SalesPerson, SUM(SaleAmount) AS TotalSales
FROM dbo.Sales
GROUP BY SalesPerson;

4.7: Count of Sales by Region

SELECT Region, COUNT(*) AS SaleCount
FROM dbo.Sales
GROUP BY Region;

4.8: Average Sale per Region

SELECT Region, AVG(SaleAmount) AS AvgSale
FROM dbo.Sales
GROUP BY Region;

🎬 Watch the Full Tutorial

Blog post written with the help of ChatGPT.