The formula expression language DAX (Data Analysis Expressions) is applicable to a variety of BI and visualisation tools. Because the entire code is contained within a function, DAX is also known as a function language. There are two data types in DAX programming formulas: numeric and other. While Other includes string and binary object, Numeric includes integers, money, and decimals.
What is DAX?
The acronym DAX stands for Data Analysis Expressions. Microsoft created this language to interact with data in a number of their platforms, including Power BI, PowerPivot, and SSAS tabular models. It is intended to be straightforward and simple to learn while demonstrating the strength and adaptability of tabular models. You might liken it to Excel formulas taken to the next level.
Using DAX will truly unleash the capabilities of Power BI.
I have reached a point where I use a lot of the code in my daily work even though I am still far from a DAX expert and have coworkers who are beginning to ask more and more questions about it. I decided to write this article about why you should (or shouldn’t) use this tool from the data science/data analysis toolbox as a result.
Essential Qualities of DAX Functions
To perform dynamic computations, DAX Functions contain formulas referred to as Measures. You can define your Measures using the DAX formula bar, and these Measures have the property of changing their values based on the situation. Additionally, measures give you the freedom to switch between tables without losing any functionality.
The row-level security of your data tables is always maintained by DAX Functions. A DAX evaluation always yields a boolean result in order to guarantee this (True or False). This limits the number of rows that can be set at once and prevents other users from accessing the assigned row. Additionally, DAX functions employ filters in order to maintain the relationship that is currently in use.
The DAX library provides calculated columns for storing the results of computations you do on data. These procedures are typically performed during a data refresh and include two or more columns. Additionally, these Calculated Columns are made to carry out row-level calculations and then create a new column that contains the results.
You can use several function types in Power BI to analyse data and add new columns and metrics. It consists of operations from several categories, including
DAX has a number of aggregate functions.
Other counting functions in DAX include −
- Logical Functions
Following are the collection of Logical functions −
- DATE Functions
- INFORMATION Functions
DAX Functions for Power BI: Date and Time Functions
DATE: The pre-specified date is returned by this function as output in datetime format. It works using the syntax shown below:
DATE(<year>, <month>, <day>)
DATEVALUE: This function transforms a date’s textual representation into a datetime format. It works using the syntax shown below:
TODAY: The following syntax is used when this function is in operation and returns the current date as output:
WEEKDAY: Using a date as its argument, this function produces a number (1–7) that represents the day of the week for that date. It works using the syntax shown below:
HOUR: This function provides a number that represents the current hour ( 0 for 12:00 A.M. and 23 for 11:00 P.M.). It works using the syntax shown below:
Information Functions for DAX in Power BI
The output of DAX Information functions is either True or False after analysis of the input argument. This function class takes one or more cells or rows from your Power BI table as parameters. According to DAX, the following operations are classified as informational:
Depending on the values for the referred columns, this function either returns true or false. It returns true if all of the values are present; otherwise, it returns false. It works using the syntax shown below:
CONTAINS(<table>, <columnName>, <value>[, <columnName>, <value>]…)
This function locates the row that satisfies the search columnName and search value criteria in their entirety and returns the value from the result columnName. It works using the syntax shown below:
LOOKUPVALUE( <result_columnName>, <search_columnName>, <search_value>[, <search_columnName>, <search_value>]…)
During connection setup, you provided the system with your domain and user name, which are returned by this function. It works using the syntax shown below:
After examining the input value, this function returns true for blank and false for any other value. It works using the syntax shown below:
The other important functions under Information Functions are as follows:
DAX Functions for Power BI: Logical Functions
DAX Logical Functions evaluate a certain input expression containing logical operators and provide a True or False output. The Logical functions work on evaluating a logical expression and are different from the Information functions which test the input argument by matching it to the stored data. The following functions fall under the Logical classification in DAX:
This function returns true if both arguments present in the input expression are valid, else it returns false. It operates using the following syntax: AND(<logical1>,<logical2>)
NOT: The value of the input expression is changed by this function to its polar opposite. This suggests that it can switch between being true and false. It works with the syntax shown below:
OR: If any of the arguments present in the input expression are valid, this function returns true; otherwise, it returns false. It works with the syntax shown below:
SWITCH: Using a list of values and an input expression, this function compares the results and returns one of the possible results. It works using the syntax shown below:
SWITCH(“expression”, “value,” “result,” “value,” result,”…”, “else,”)
IF: If the first argument is true, this function checks the condition and, based on that, returns a true or false condition. It works using the syntax shown below:
If (logical test), “value if true,” ,”value if false,”
The following are some additional crucial logical functions:
Trigonometric and mathematical DAX functions for Power BI
You may easily carry out fundamental mathematical operations using the DAX mathematical and trigonometric functions, which operate similarly to their Excel equivalents. The DAX category “Mathematical & Trigonometric” includes the following functions:
ABS :The following syntax is used by the ABS function to return the input number’s absolute value:
ACOS :The inverse cosine value of a given input integer is returned by the ACOS function. The angle it returns is measured in radians, from 0 to pi. It works using the syntax shown below:
CEILING: This function returns the nearest roundup value (integer) of the given input using the following syntax:
COMBIN:This function gives the total number of combinations that can be made from the input items. It works using the syntax shown below:
CURRENCY: This function analyses the input and outputs the result as a data type for currency. It works using the syntax shown below:
The other important functions under Mathematical & Trigonometric are as follows:
Power BI DAX Functions: Parent & Child Functions
You can manage data that is restricted in a parent-child hierarchy using the DAX Parent and Child functions. The Parent & Child category in DAX includes the following functions:
PATH: This function gives back a delimited text string containing all of the current identifiers’ parent identifiers. It works using the syntax shown below:
PATH(‘ID’ column, ‘parent’ column)
PATHITEM: This function extracts the item from a string at the specified position after reading the PATH function. It works using the syntax shown below:
PATHITEM(“path,” “position,” “type,”
The following are some additional crucial responsibilities under Parent & Child:
DAX Functions for Power BI: Statistical Functions
Averages, approximations, and many other statistical formula operations are supported by DAX statistical functions. The statistical functions listed below are classified as such in DAX:
The ADDCOLUMNS function adds calculated columns to the table that is supplied. The syntax it uses is ADDCOLUMNS(table>, name>, expression>[, name>, expression>]…)
AVERAGE: Using the following syntax, this function determines and returns the arithmetic mean of all the values in a column of input data:
BETA.INV: This function returns the beta cumulative probability density function’s inverse value. It works using the syntax shown below:
The other important functions under Statistical are as follows:
DAX Functions for Power BI: Text Functions
You can use the String data type while working with tables and columns using DAX Text methods. With the help of these functions, you may alter different aspects of a string, search for specific text inside strings, manage date formats, and much more. The Text category in DAX includes the following functions:
The syntax for this function, which just returns a blank, is as follows:
The first character in the input text string corresponds to the numeric value (code) that this function returns. The syntax for IT is as follows:
CONCATENATE: Using the following syntax, this function joins two input text strings into one text string.
EXACT: This function compares two text strings and returns a true value if they are precisely the same. It works using the syntax shown below:
Find:A text string’s beginning within another input text string is returned by the FIND function. It works using the syntax shown below:
FIND(“find text,” “inside,” “start num,”
The other important functions under Text are as follows:
DAX Functions for Power BI: Other Functions
DAX Functions for Power BI: Other Functions
This category contains DAX Functions that can not be grouped in a specific class due to their unique characteristic properties. The following functions fall under the Other classification in DAX:
Benefits of DAX Functions
By itself, Power BI offers you amazing functionality. However, adding DAX Functions to Power BI will further your efforts and give you the advantages listed below:
Many cutting-edge Power BI features can be used thanks to the DAX library. For instance, you can use DAX’s select, join, filter, and many other commands to dynamically change your data. The Power BI dashboard will then automatically generate data, including Calculated Columns, Tables, and Measures, based on the input that users provide.
You may add intelligence to your Power BI Dashboards by using DAX. Utilizing Power BI’s Calculated Columns and Measures to limit the data that your Dashboard will retrieve and visualise makes this possible. Your latency and complete data can both be increased by a well-written DAX expression.