DAX in Power BI: As a formula language
Table of Contents
DAX in Power BI is a powerful formula language. It not only allows users to create custom measures and calculations but also helps in transforming raw data into meaningful insights. Therefore, by mastering DAX, you can uncover trends, analyse patterns, and make smarter, data-driven decisions with ease.
In this blog post, we will look at DAX as a formula language in Power BI and how it differs from Excel and M language.
Learn more about DAX in our blog: Introduction to DAX and its Data Types
DAX as a formula language
DAX is a formula language, which means there is one formula call with many parameters. This function call can also contain other function calls as parameters. For Power BI Desktop, all the DAX code is typed in the formula bar shown below. The measure/column tools tab additionally provides all the information related to the measure or column, respectively.
A DAX expression consists of a formula followed by a measure or a column reference. Now, let’s look at the structure of a typical DAX expression.
- This is the name of the expression that you are going to create.
- The equal sign represents the beginning of a DAX expression.
- Formula represents the calculation that you want to perform.
- Name of Table.
- Name of Column.
Now, let’s map this to a simple example that calculates the sum of Sales Amount from the sales table using the SUM function.
Vertipaq engine in DAX
Vertipaq is the compression engine of Microsoft Power BI. As soon as the data is loaded in Power BI, Vertipaq engine performs a series of algorithms on the data to compress it as much as possible. This optimizes the memory footprint and DAX query time in Power BI.
Learn more about Vertipaq engine in our blog: Vertipaq Engine and Best Practices
The Vertipaq engine uses the following three algorithms to compress the data:
Value Encoding:
Value encoding discovers the mathematical relationship between different values in a column and uses this relationship for the compression of data. Then, the data is encoded in the first stage and then stored. In the second stage, the data is decoded, and the original values are returned. Value encoding is performed only for integers and not for strings and floating-point values.
Dictionary or Hash Encoding:
Dictionary encoding builds a dictionary of the distinct values of a column, and then it replaces the column values with the indexes of the dictionary. Therefore, dictionary encoding converts column values into integers only. This reduces memory usage and optimizes the workflow.
Run Length Encoding (RLE):
Run-length encoding optimizes the size of the data set by avoiding repetitive values. Furthermore, RLE creates a relatively complex code structure containing the value only once, and the number of contiguous rows containing that value.
Difference between DAX and EXCEL functions
Many DAX functions have the same name and general behavior as EXCEL functions, but they work in completely different ways. Now, let’s look at some significant differences between these two languages.
Excel | DAX | |
Referencing | Cell references are used to define calculation | Column references are used to define calculations |
Evaluation context | No evaluation context exists | Row and filter contexts exist |
Variant data type | Supports Variant data type in a column | Does not support variant data type in a column |
Date and Time functions | Date and time functions return an integer | DAX date and time functions return date and time value. |
Difference between DAX and M
M and DAX, both are used in Power BI to transform, filter, and analyze data. Although both of these languages look similar, they operate independently of each other. Here’s a list of ways in which they differ.
M Language | DAX | |
Functionality | Query language to Shape and Transform Data | Functional language to build calculations and model data |
Usage
| Used for Query-Time Transformations | Used for In-Memory Transformations |
Scope
| M is used to preprocess data inside the query editor. | Enriches data once the data is loaded into the data mode |
Application
| M is a mashup language that works on multiple data sources, therefore uses commands to shape and transform the data. | DAX is a formula language; therefore, it uses formulas to develop new data columns and measures. |
Suitability | M is best suited for ETL. | DAX is best suited for analytics. |
Best Practices in DAX
DAX code can be error-free and easier to read when the following practices are followed:
- Use descriptive names for variables, measures, and columns.
- Follow a naming convention.
- Format your code.
- Use the correct data type for columns and measures.
- Never use table names for measure reference.
- Always use table names for column reference.
- Split your calculations in small blocks using variables.
- Write once and re-use measures.
- Remove unnecessary prefixes before importing the tables.
- Check the measures using matrix visuals.
- Improve code readability by using variables.
- Sort the alphabetic column with a suitable numerical column.
Conclusion
For anyone hoping to fully utilize their data, Power BI’s DAX is a crucial tool. It is a formula language that enables you to efficiently generate meaningful insights, analyze trends, and perform custom calculations. With DAX, you can create clear, efficient, and potent DAX expressions by comprehending its structure, utilizing the Vertipaq engine, and adhering to best practices. Additionally, understanding the distinctions between DAX, Excel functions, and the M language enables you to make efficient use of each tool in your data workflow. Ultimately, becoming proficient with DAX enables you to improve your Power BI reports and make more intelligent, data-driven decisions.
FAQs
Power BI uses a formula language called DAX (Data Analysis Expressions) to generate unique calculations, measures, and calculated columns for data analysis.
Although some DAX functions have names that are similar to those of Excel functions, DAX is more powerful for data modeling because it works with row and filter contexts and employs column references rather than cell references.
While DAX is used for computations and analytics once the data is loaded into Power BI, M is a query language used to shape and transform data before it is loaded.
Further Learning and Resources
To learn more about Power BI, check out our courses here:
- Power BI Essentials
- Power BI Report Design
- Power BI Advanced
- Power BI DAX Essentials
- Power BI Service Course
- ChatGPT Essentials
Want to learn how Microsoft 365 Copilot transforms everyday work with AI? Check out our Course:
Want to learn more about Power BI and how to make reports more efficiently?
Power BI training in Australia: We offer comprehensive training sessions across various cities, including :
Power BI Crash Course eBook: Download our detailed guide to take your Power BI expertise to the next level, covering topics from basics to advanced with practical examples and step-by-step instructions. (Limited time offer)
Download the Beginner’s Guide to Power BI
Ready to enhance your Power BI skills? Sign up for our training courses and explore our wide range of resources designed to elevate your data analytics capabilities.
Contact Us: Make an enquiry about our Power BI courses and find the proper training for you.