Exploring SQL and Excel in Financial Analysis & Reporting

Dr Lim Thou Tin
DataFrens.sg
Published in
4 min readFeb 6, 2024
Photo by AbsolutVision on Unsplash

Finance and accounting, which are heavily focused on numerical computations, often utilize Excel. However, SQL is also recognized for its strengths in handling, sorting, and modifying large volumes of data. Moreover, SQL excels in executing complex mathematical operations, making it a crucial tool for financial analysis and a viable alternative to Excel.

The mathematical functions SQL employs in financial contexts are essentially the same as the standard mathematical operations even of Excel. SQL’s role is to enhance these operations, offering a means to utilize them more effectively and extensively on large data sets. Fundamentally, these involve basic arithmetic operations like addition, subtraction, multiplication, and division. Yet, their integration with other SQL functionalities enables the generation of a diverse and insightful range of financial metrics as shown in the table below:.

These common numeric/math functions are integral to SQL and can be used extensively for financial data analysis and reporting. They allow for efficient and powerful data processing directly within the database, reducing the need for external data manipulation tools eg.

SELECT SUM(Revenue) — SUM(Cost) AS Profit
FROM Sales

It can be observed that Excel handling of data operations parallels functions used in SQL, especially when it comes to basic arithmetic and aggregation tasks.

The SUM function in SQL is analogous to the SUM function in Excel.

The operation of subtracting the sum of costs from the sum of revenues (SUM(Revenue) — SUM(Cost)) in SQL is similar to subtracting the cell with the total cost from the cell with the total revenue in Excel.

Both SQL and Excel are handling aggregate data operations — in SQL, it’s across the entire Sales table, while in Excel, it’s across the range of rows where the data is located.

The following query will output a table with three columns — Month, AvgRevenue, and TotalProfit. For each month present in the Sales table, it will show the average revenue (rounded to two decimal places) and the total profit. This kind of query is very useful for financial reporting where monthly revenue and profit trends are important for business analysis.

SELECT Month,
ROUND(AVG(Revenue), 2) AS AvgRevenue, SUM(Profit) AS TotalProfit
FROM Sales

Similarly, it can be seen that the AVERAGE function along with the ROUND function can be found to be used in Excel expressed as =ROUND(AVERAGE(B2:B100), 2). In SQL, the query implicitly groups the results by Month since Month is included in the SELECT statement along with aggregate functions. However, in Excel, a pivot table needs to be grouped by Month with the Month field in the Rows area, and then use the AVERAGE and SUM functions in the Values area to calculate average revenue and total profit, respectively, for each month.

Some of the date and time functions in SQL can be used to manipulate, format, and calculate data based on dates and times. These functions are essential in a database for various operations like data analysis, reporting, and scheduling. They allow for performing of tasks like extracting specific parts of a date/time, calculating differences between dates, or formatting date/time values in a more readable form(shown in the table below).

These functions are widely used for reporting, data analysis, and even in business logic to handle time-related data efficiently. They provide robust tools for managing and interpreting the temporal aspects of data in a relational database. The following query is a practical example of how SQL can be used in financial operations to analyze customer spending patterns, which can be crucial for financial analysis and reporting.

SELECT CustomerID, SUM(Amount) AS TotalSpending
FROM CustomerTransactions
WHERE TransactionType != ‘Deposit’ AND YEAR(TransactionDate) = 2023
GROUP BY CustomerID
HAVING SUM(Amount) > 10000
ORDER BY TotalSpending DESC;

In Excel, to replicate a specific SQL query, first apply filters to exclude Deposit transaction types and non-2023 dates, then use a Pivot Table to group data by CustomerID, sum the Amount per customer, filter for total spending over $10,000, and sort the results in descending order, possibly requiring a helper column to filter by year.

As shown in the table below, it can be seen that while SQL and Excel do share some common functionalities in data manipulation and analysis, they differ significantly in terms of scalability, data handling capabilities, user interface, and the complexity of operations they can perform. SQL is more suited for managing large datasets and complex queries, whereas Excel is more user-friendly and versatile for smaller datasets, data visualization, and basic analyses.

Having a background in Excel can significantly help to smoothen the learning curve for SQL, as both tools involve key data handling skills like sorting, filtering, and manipulating datasets. Excel users are already familiar with the use of functions and formulas, a mindset that is directly applicable to SQL’s data function application. Additionally, the basic understanding of data organization and analysis, as well as concepts like data aggregation (summing, averaging, finding minimums and maximums), which are integral to Excel, are also foundational in SQL. While the specific syntax may differ, the core concepts and analytical thinking are similar, making the transition from Excel to SQL more intuitive for learners.

--

--

Dr Lim Thou Tin
DataFrens.sg

An IT & business strategist with a doctorate in Knowledge Management & Intelligent Systems. Experienced in corporate IT & educator at global institutions.