top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

How I Solved a 1.5 million Row Healthcare Data Performance Using SQL Aggregation?

Jan 10
3 min read

When I started data analysis journey leaning tools like Tableau and Power BI. These powerful visualization platforms promise meaningful insights through KPIs, metrics, and interactive dashboards. The dataset I encountered had 1.5 million rows with patient IDs, biomarkers, and clinical measurements. Many patient IDs were duplicated across multiple visits, tests, and treatments. When I attempted to load this massive dataset into Power BI, the performance issues were immediately apparent. The loading process was painfully slow, taking over 15 minutes.  the data finally loaded, I discovered discrepancies for example some rows were missing, and certain values didn't match the original dataset. This was unacceptable for healthcare analytics where accuracy is paramount. Medical decisions and patient care depend on precise data analysis. A missing row could mean overlooking a critical patient biomarker or some other extremely important measure. An incorrect value could lead to false conclusions about treatment effectiveness.

 

Performance Testing

Tableau and Power BI are exceptional tools, but they have limitations when dealing with raw, unprocessed data at scale. Loading millions of granular rows taxes system memory and processing power. The tools struggle to:

  • Process redundant patient records efficiently

  • Calculate aggregations on-the-fly during visualization

  • Maintain data integrity with extremely large files

  • Provide responsive, real-time dashboard interactions

I realized that uploading raw data directly into these visualization tools wasn't the optimal approach. The problem wasn't with Tableau or Power BI. I was simply using them incorrectly. These tools perform best when fed clean, appropriately sized datasets. Instead, I needed to clean and pre-aggregate the data before visualization, treating the visualization layer as the final step in the data analysis.

SQL as the Solution

This is when SQL became my game-changer. As a beginner learning SQL, I was fascinated by how efficiently it handles large datasets. SQL's aggregate functions SUM, AVG, COUNT, MIN, MAX allow you to condense millions of rows into meaningful summaries. Views enable you to combine multiple tables and create pre-aggregated datasets that are perfectly sized for visualization tools. SQL gave me complete control over data quality. I could identify and handle duplicates, manage null values, standardize data formats, and ensure every record met quality standards before it ever reached the visualization layer. This preprocessing step became the foundation of reliable analytics.

The Three-Stage Approach

Here's how SQL aggregation transformed my workflow:

Stage 1: Raw Data

My original dataset contained 1,500,000 rows with individual patient test results, each record showing:

  • Patient ID

  • Date

  • Biomarker Type (glucose, cholesterol, blood pressure, etc.)

  • Visit ID

Stage 2: SQL Aggregation

Using SQL, I created aggregated views that rolled up the data by patient, calculating:

  • Average biomarker values per patient

  • Number of visits per patient

  • Latest test date

  • Minimum and maximum values for each biomarker

SQL

CREATE VIEW patient_summary AS

SELECT 

    patient_id,

    COUNT (DISTINCT visit_id) as total_visits,

    AVG (glucose) as avg_glucose,

    AVG (cholesterol) as avg_cholesterol,

    MAX (test_date) as last_visit_date

FROM patient_tests

GROUP BY patient_id;

This reduced the dataset from 1.5 million rows to just 50,000 unique patients—a 97% reduction!

Stage 3: Visualization-Ready Data

The aggregated view loaded into Power BI in under 2 minutes with 100% data accuracy. Dashboards became responsive, KPIs calculated instantly, and I could focus on deriving insights rather than troubleshooting performance issues.


Measurable Improvements

The transformation was dramatic:

Time Efficiency:

  • Raw data load time: 15+ minutes

  • Aggregated data load time: <2 minutes

  • Improvement: 93% faster

Data Volume:

  • Raw rows: 1,500,000

  • Aggregated rows: 50,000

  • Improvement: 97% reduction

Data Accuracy:

  • Raw data: Incomplete, missing values

  • Aggregated data: 100% accurate, complete dataset

Conclusion:

Working with large healthcare datasets taught me that effective data analysis isn't just about visualization tools—it's about the entire data pipeline. SQL aggregation serves as the critical bridge between raw data and visualization, ensuring:

  1. Clean data enters your visualization tools

  2. Performance remains optimal for interactive analysis

  3. Accuracy is maintained throughout the process

  4. Insights are derived from meaningful, not overwhelming, data

For anyone working with large datasets in healthcare or any other field, learning SQL before diving deep into visualization tools is crucial. Pre-process, aggregate, and clean your data using SQL, then leverage the full power of Tableau and Power BI to create impactful, accurate dashboards that truly serve your stakeholders.

The combination of SQL's data processing power and modern visualization tools' presentation capabilities is the winning formula for effective data analysis.

 
 

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page