HomeCodeSQL ConvertersSQL to DAX Converter

SQL to DAX Converter

Convert SQL queries to DAX expressions seamlessly with our SQL to DAX Converter. Easily handle SELECT, JOIN, WHERE, and GROUP BY conversions for Power BI and Power Pivot.

Basic SELECT Query with SUM and WHERE Clause

Input SQL:

SELECT SUM(SalesAmount) FROM Sales WHERE Year = 2023;

Expected DAX Output:

CALCULATE(SUM(Sales[SalesAmount]), Sales[Year] = 2023)

Explanation: In DAX, CALCULATE() is used to apply filters to an aggregation like SUM(). The SQL WHERE clause is converted into the filter argument of CALCULATE().

GROUP BY Query with SUM

Input SQL:

SELECT City, SUM(SalesAmount) FROM Sales GROUP BY City;

Expected DAX Output:

SUMMARIZE(Sales, Sales[City], "Total Sales", SUM(Sales[SalesAmount]))

Explanation: In DAX, SUMMARIZE() is used for grouping data. It groups the data by the City column and returns a summary of Total Sales for each city using the SUM() function.

Join Query (SQL INNER JOIN Equivalent)

Input SQL:

SELECT Customers.CustomerName, Sales.SalesAmount 
FROM Customers 
INNER JOIN Sales ON Customers.CustomerID = Sales.CustomerID;

Expected DAX Output:

CALCULATE(SUM(Sales[SalesAmount]), RELATED(Customers[CustomerName]))

Explanation: In DAX, relationships between tables are managed using the RELATED() function. The SQL INNER JOIN is implied by the relationships in the model, so DAX doesn’t explicitly require a JOIN.

DISTINCT Query

Input SQL:

SELECT DISTINCT ProductCategory FROM Products;

Expected DAX Output:

VALUES(Products[ProductCategory])

Explanation: The DAX function VALUES() returns distinct values from a column, which is equivalent to SQL’s SELECT DISTINCT operation.

COUNT with Multiple Conditions (AND in WHERE clause)

Input SQL:

SELECT COUNT(*) FROM Sales WHERE Year = 2023 AND Region = 'North';

Expected DAX Output:

CALCULATE(COUNTROWS(Sales), Sales[Year] = 2023, Sales[Region] = "North")

Explanation: In DAX, multiple conditions can be passed into CALCULATE(). COUNTROWS() is used to count the rows that satisfy the conditions (equivalent to SQL’s COUNT(*)). The SQL WHERE clause with AND is translated to multiple filter conditions inside CALCULATE().

SQL to DAX Conversion Table: Key Differences and Equivalents

Here is a list that outlines the key differences between SQL and DAX, highlighting how to convert common SQL queries and operations into their DAX equivalents.

SQL ConceptSQL SyntaxDAX EquivalentExplanation
Basic SELECTSELECT column FROM tableCALCULATE(SUM(table[column]))DAX uses CALCULATE to evaluate expressions and apply filters.
SUM FunctionSELECT SUM(column) FROM tableSUM(table[column])DAX uses SUM() the same way as SQL, for aggregating values.
COUNT FunctionSELECT COUNT(column) FROM tableCOUNT(table[column]) or COUNTROWS(table)COUNT() or COUNTROWS() are used in DAX to count values or rows.
DISTINCTSELECT DISTINCT column FROM tableVALUES(table[column])DAX uses VALUES() to return distinct values.
GROUP BYSELECT column, SUM(column2) FROM table GROUP BY columnSUMMARIZE(table, table[column], "Total", SUM(table[column2]))DAX uses SUMMARIZE() to perform groupings.
WHERE Clause (Filter)SELECT column FROM table WHERE conditionCALCULATE(SUM(table[column]), table[condition])DAX uses CALCULATE() to apply filters like the WHERE clause.
Multiple WHERE ConditionsSELECT column FROM table WHERE condition1 AND condition2CALCULATE(SUM(table[column]), table[condition1], table[condition2])Multiple conditions in WHERE are added as filters in CALCULATE().
JOINs (INNER JOIN)SELECT a.column, b.column FROM a INNER JOIN b ON a.key = b.keyCALCULATE(SUM(a[column]), RELATED(b[column]))DAX uses RELATED() to fetch related data, implying a join.
LEFT JOINSELECT a.column, b.column FROM a LEFT JOIN b ON a.key = b.keyLOOKUPVALUE(b[column], b[key], a[key])DAX uses LOOKUPVALUE() to replicate a LEFT JOIN.
COUNT with FiltersSELECT COUNT(*) FROM table WHERE conditionCALCULATE(COUNTROWS(table), table[condition])COUNTROWS() in DAX counts rows while applying filters.
AVERAGE FunctionSELECT AVG(column) FROM tableAVERAGE(table[column])DAX uses AVERAGE() for calculating the average.
MAX FunctionSELECT MAX(column) FROM tableMAX(table[column])MAX() in DAX finds the maximum value from a column.
MIN FunctionSELECT MIN(column) FROM tableMIN(table[column])MIN() in DAX finds the minimum value from a column.
LIMITSELECT column FROM table LIMIT nN/A (handled by visual filtering in Power BI)DAX doesn’t have a LIMIT function. Limit rows using filters in visuals.
ORDER BYSELECT column FROM table ORDER BY column ASC/DESCN/A (handled by sorting in visuals)DAX doesn’t explicitly support ORDER BY. Sorting is managed by visuals.
CASE StatementSELECT CASE WHEN condition THEN result ELSE result2 END FROM tableSWITCH(TRUE(), condition, result, condition2, result2, ...)DAX uses SWITCH() for CASE logic. IF() can also be used for simple conditions.
IS NULL / IS NOT NULLSELECT column FROM table WHERE column IS NULLISBLANK(table[column])DAX uses ISBLANK() to check for null values.
NOT NULLSELECT column FROM table WHERE column IS NOT NULLNOT(ISBLANK(table[column]))DAX uses NOT(ISBLANK()) to check for non-null values.
COALESCE / IFNULLSELECT COALESCE(column1, column2) FROM tableCOALESCE(table[column1], table[column2])DAX also uses COALESCE() to return the first non-null value.
IF StatementSELECT IF(condition, true_value, false_value)IF(condition, true_value, false_value)IF() functions are similar in both SQL and DAX.
UNIONSELECT column FROM table1 UNION SELECT column FROM table2UNION(table1, table2)DAX uses the UNION() function to combine rows from two tables.
EXCEPTSELECT column FROM table1 EXCEPT SELECT column FROM table2EXCEPT(table1, table2)EXCEPT() in DAX returns rows present in the first table but not in the second.
INTERSECTSELECT column FROM table1 INTERSECT SELECT column FROM table2INTERSECT(table1, table2)INTERSECT() in DAX returns rows common to both tables.
DATE FunctionsSELECT DATE(column)DATE(year, month, day)DAX uses DATE() to handle date columns similarly to SQL.
DATEADD FunctionSELECT DATEADD(column, interval)DATEADD(table[column], interval, "MONTH"/"YEAR"/"DAY")Both SQL and DAX use DATEADD() to manipulate dates.
DATEPART FunctionSELECT EXTRACT(YEAR FROM column)YEAR(table[column])DAX uses YEAR(), MONTH(), and DAY() to extract date parts.
BETWEEN OperatorSELECT column FROM table WHERE column BETWEEN value1 AND value2CALCULATE(SUM(table[column]), table[column] >= value1, table[column] <= value2)DAX uses CALCULATE() with multiple conditions for the BETWEEN operator.
IN OperatorSELECT column FROM table WHERE column IN (value1, value2)CALCULATE(SUM(table[column]), table[column] IN {value1, value2})DAX uses IN {} for similar functionality to SQL’s IN operator.

More Tools