Scroll Top

π—¦π—€π—Ÿ and 𝗗𝗔𝗫

SQL-Tutorial

π—¦π—€π—Ÿ and 𝗗𝗔𝗫 are both powerful query languages, but they work in different ways. If you’re transitioning from SQL to Power BI, one of the biggest challenges is understanding how to translate common SQL queries into DAX formulas.
One common mistake is assuming that SUM in SQL works exactly like SUM in DAXβ€”while they look similar, their behavior can differ significantly depending on the context.

PDF LINK

InoVision

-- Basic Aggregation - Summing Sales
-- SQL Approach:
SELECT SUM(SalesAmount) AS TotalSales
FROM SalesTable;

-- DAX Equivalent:
TotalSales = SUM(SalesTable[SalesAmount])

-- Conditional Aggregation - Filtering High-Value Sales
-- SQL Approach:
SELECT SUM(SalesAmount) AS HighValueSales
FROM SalesTable
WHERE SalesAmount > 1000;

-- DAX Equivalent:
HighValueSales = CALCULATE(SUM(SalesTable[SalesAmount]), SalesTable[SalesAmount] > 1000)

-- Grouping - Total Sales by Product Category
-- SQL Approach:
SELECT ProductCategory, SUM(SalesAmount) AS TotalSales
FROM SalesTable
GROUP BY ProductCategory;

-- DAX Equivalent:
TotalSalesByCategory = SUMMARIZE(SalesTable, SalesTable[ProductCategory], "TotalSales", SUM(SalesTable[SalesAmount]))

-- Date-Based Aggregation - Year-to-Date (YTD) Sales
-- SQL Approach:
SELECT SUM(SalesAmount) AS YTDSales
FROM SalesTable
WHERE OrderDate >= 'YYYY-01-01';

-- DAX Equivalent:
YTDSales = TOTALYTD(SUM(SalesTable[SalesAmount]), SalesTable[OrderDate])
Cresta Help Chat
Send via WhatsApp