Excelgoodies logo +44 (0)20 3769 3689

What Calculations Should Be Done in SQL vs DAX?


One of the most common questions Power BI developers face isn’t how to calculate something — it’s where to calculate it.

Should the logic live in SQL?
Or should it be written in DAX?

Get this decision wrong, and you may end up with:

  • Slow reports
  • Overcomplicated models
  • Logic that’s hard to explain or change

Get it right, and your Power BI solution becomes faster, cleaner, and far easier to maintain. This article breaks down which calculations belong in SQL and which belong in DAX, based on how Power BI solutions actually behave in real-world environments.

Why This Question Keeps Coming Up

Both SQL and DAX are powerful calculation engines. And technically, many calculations can be done in either place. That’s where confusion begins.

The key difference is not capability — it’s intent:

  • SQL is designed for data preparation and consistency
  • DAX is designed for dynamic analysis and context

Understanding this distinction simplifies almost every design decision that follows.

Calculations That Belong in SQL

SQL is best suited for calculations that are stable, repeatable, and foundational. These are calculations that:

  • Don’t change based on user interaction
  • Apply consistently across all reports
  • Define how the business understands its data

Typical SQL-Friendly Calculations
 

  • Standard business rules
    (e.g. net sales, valid transactions, exclusions)
  • Row-level derived columns
    (e.g. status flags, categories, classifications)
  • Data cleansing and normalization logic
  • Pre-aggregations for very large datasets
  • Surrogate keys and identifiers

These calculations benefit from being:

  • Centralised
  • Reusable
  • Executed once at the source

SQL ensures consistency at scale.

Calculations That Belong in DAX

DAX excels at context-aware, user-driven calculations. These are calculations that:

  • Change based on filters and slicers
  • Depend on report context
  • Are evaluated at query time

Typical DAX-Friendly Calculations
 

  • KPIs and measures
  • Ratios and percentages
  • Time intelligence (YTD, MTD, YoY)
  • Running totals
  • Comparisons across dimensions

DAX is designed to answer questions like:
“What does this number mean in this context?”

Trying to force this logic into SQL usually results in rigid queries and limited flexibility.

Where Teams Commonly Go Wrong

Most issues arise when one tool is used to do everything.

Common Anti-Patterns
 

  • Building complex KPIs in SQL that never change
  • Rewriting the same SQL logic again in DAX
  • Using DAX to compensate for poor SQL modelling
  • Hiding important business logic deep inside SQL views

These choices often lead to:

  • Performance bottlenecks
  • Confusing models
  • Difficult troubleshooting
  • Logic that only one person understands

The problem isn’t SQL or DAX — it’s misplaced responsibility.

A Simple Decision Framework

A practical way to decide is to ask:
Does this calculation depend on report context?

  • Yes → DAX
  • No → SQL

And then ask:
Is this logic foundational to how the business defines data?

  • Yes → SQL
  • No / Analytical → DAX

This mental model avoids most design mistakes.

Performance Considerations (Without Overthinking)

Performance is often used as the justification for pushing logic into SQL. While SQL can handle large volumes efficiently, performance suffers when:

  • SQL queries become too complex
  • Logic becomes difficult to optimise
  • Minor changes require database changes

In many cases, well-structured SQL + efficient DAX measures performs better than over-engineered SQL alone.
The real performance win usually comes from:

  • Clean data models
  • Correct granularity
  • Clear separation of logic

This balance between SQL and Power BI is where many reporting solutions either scale smoothly — or struggle quietly. For readers interested in how this balance is applied in practice, this Power BI + SQL approach is explained here: Power BI with SQL

Collaboration and Maintainability Matter

Another overlooked factor is who maintains the logic.

  • SQL logic is often owned by data or platform teams
  • DAX logic is usually owned by report developers

Placing calculations in the wrong layer can slow down changes simply because the wrong team controls it. Good Power BI design considers people and processes, not just technical capability.

Final Thought

The question isn’t:
“Can I calculate this in SQL or DAX?”

The better question is:
“Where will this calculation be easiest to understand, maintain, and explain?”

SQL and DAX each have a clear role. When used together — deliberately — Power BI solutions become faster, clearer, and far more resilient.


Learning How SQL and DAX Work Together in Practice

For those looking to understand how calculations should be split across SQL, DAX, and Power BI, the Power BI + SQL Course by ExcelGoodies focuses on real reporting scenarios rather than isolated tools.

Check the Upcoming batch details
 

Editor’s Note

This article reflects common calculation design discussions observed across Power BI reporting projects where SQL preparation and DAX modelling intersect. The focus is on practical decision-making rather than theoretical optimisation.

Insights compiled with inputs from the ExcelGoodies Trainers & Power Users Community.
 

MS-SQL

New

Next Batches Now Live

Power BIPower BI
Power BISQL
Power BIPower Apps
Power BIPower Automate
Power BIMicrosoft Fabrics
Power BIAzure Data Engineering
Explore Dates & Reserve Your Spot Reserve Your Spot