SQL to DAX Converter
Transform SQL database dumps into DAX (Data Analysis Expressions) table expressions for Power BI and Analysis Services
SQL Input
DAX Output
About SQL to DAX Converter
Convert SQL database dumps (CREATE TABLE and INSERT statements) to DAX (Data Analysis Expressions) table expressions for Power BI and SQL Server Analysis Services. DAX is a formula language used for data modeling, calculations, and creating calculated tables in Microsoft's business intelligence tools.
Key Features
- Three DAX Formats: TABLE(), DATATABLE(), and ROW()+UNION() expressions
- Automatic Type Detection: Detects INTEGER, DOUBLE, BOOLEAN, DATETIME, and STRING types
- BLANK() Support: Handles NULL and empty values with BLANK() function
- Custom Table Naming: Configure table name for your Power BI model
- Usage Comments: Optional comments with instructions
- Smart Parsing: Extracts column names and data from SQL dumps
- File Download: Save as .dax file
How to Use
- Input SQL Data: Paste your SQL CREATE TABLE and INSERT statements or upload a .sql file
- Choose Format: Select DATATABLE(), TABLE(), or ROW()+UNION() format
- Set Table Name: Configure the name for your calculated table
- Toggle Comments: Enable or disable usage instructions
- Copy or Download: Use the Copy or Download button to save your DAX expression
DAX Format Options
DATATABLE() - Recommended:
- Includes column names and data types
- Most readable and maintainable
- Best for structured data with known types
- Supports INTEGER, DOUBLE, BOOLEAN, DATETIME, STRING
TABLE() - Simple:
- Creates table without column names
- Compact syntax for simple data
- Column names assigned automatically (Column1, Column2, etc.)
- Good for temporary calculations
ROW() + UNION() - Flexible:
- Most flexible format with named columns
- Each row defined separately with ROW()
- Combined with UNION() function
- Best for dynamic or conditional data
Example Conversion
SQL Input:
CREATE TABLE products ( id INT, name VARCHAR(100), price DECIMAL(10,2), in_stock BOOLEAN ); INSERT INTO products VALUES (1, 'Laptop', 999.99, true); INSERT INTO products VALUES (2, 'Mouse', 24.99, false);
DAX Output (DATATABLE format):
products = DATATABLE(
id, INTEGER,
name, STRING,
price, DOUBLE,
in_stock, BOOLEAN
,
{
{1, "Laptop", 999.99, TRUE},
{2, "Mouse", 24.99, FALSE}
}
) DAX Output (ROW + UNION format):
products = ROW( id, 1, name, "Laptop", price, 999.99, in_stock, TRUE ), UNION( ROW( id, 2, name, "Mouse", price, 24.99, in_stock, FALSE ) )
Common Use Cases
- Power BI Calculated Tables: Create tables from SQL data in Power BI Desktop
- Data Modeling: Build dimension and fact tables for analysis
- Test Data: Generate sample data for testing reports
- Reference Tables: Create lookup tables and mappings
- Static Data: Include configuration or metadata tables
- Analysis Services: Use in SSAS tabular models
DAX Data Types
- INTEGER: Whole numbers (64-bit signed integer)
- DOUBLE: Floating-point numbers (double precision)
- BOOLEAN: TRUE or FALSE values
- DATETIME: Date and time values
- STRING: Text values (Unicode)
- BLANK(): Represents NULL or missing values
Using in Power BI
- Open Power BI Desktop
- Go to Modeling Tab: Click on the "Modeling" ribbon
- New Table: Click "New Table" button
- Paste DAX: Paste the generated DAX expression
- Press Enter: The table will be created in your model
- Use in Reports: Add fields to visualizations
Best Practices
- Use DATATABLE(): Preferred format for clarity and type safety
- Name Tables Clearly: Use descriptive names for calculated tables
- Handle BLANK(): Use BLANK() for NULL values instead of empty strings
- Type Consistency: Ensure all values in a column match the declared type
- Performance: Calculated tables are stored in memory, keep them reasonably sized
- Documentation: Include comments for complex expressions
Power BI Integration
Calculated Tables:
- Created using DAX expressions
- Stored in the data model
- Refreshed when model is refreshed
- Can be used in relationships
Relationships:
- Connect calculated tables to other tables
- Use in data model relationships
- Enable cross-filtering and drill-through
Measures and Calculations:
- Reference calculated table columns in measures
- Use in calculated columns
- Filter and aggregate data
Analysis Services Support
- SSAS Tabular: Full support for calculated tables
- Azure Analysis Services: Cloud-based tabular models
- Power BI Premium: Enhanced features and performance
- Compatibility Level: Ensure compatibility with your SSAS version
Limitations
- Memory Usage: Calculated tables consume memory in the model
- Refresh Time: Large tables increase refresh duration
- Static Data: Data doesn't update automatically from source
- Size Limits: Consider model size limits in Power BI
Supported SQL Syntax
- CREATE TABLE: Extracts column names for DAX table
- INSERT INTO: Parses data values for table rows
- Data Types: Handles all SQL data types (VARCHAR, INT, DECIMAL, BOOLEAN, DATE, etc.)
- Quoted Strings: Handles single and double quotes with proper escaping
DAX Resources
- Microsoft Docs: Official DAX function reference
- SQLBI: DAX patterns and best practices (sqlbi.com)
- DAX.guide: Comprehensive DAX function guide
- Power BI Community: Forums and support
Privacy & Security
All conversions happen locally in your browser. Your SQL data is never uploaded to any server, ensuring complete privacy and security.
