SQL and DAX: three habits for fast, readable queries
In SQL, select only the columns you need and filter early. In DAX, store intermediate results in variables (VAR) so they are evaluated once.
Tip of the week
In SQL, select only the columns you need and filter early. In DAX, store intermediate results in variables (VAR) so they are evaluated once.
SELECT o.id, o.total, c.name
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id
WHERE o.created_at >= DATE '2026-01-01'
ORDER BY o.total DESC;
Ventas YTD Margen =
VAR Ventas = [Ventas Totales]
VAR Costo = [Costo Total]
RETURN DIVIDE(Ventas - Costo, Ventas)
Quick rules
- Avoid
SELECT *in production. - Use
DIVIDEin DAX to avoid division-by-zero errors. - One measure, one responsibility: compose measures instead of duplicating logic.
View syntax error fix guide: SQL and DAX formatting rules: a quick guide with examples