DAX Functions Flashcards
APPROXIMATEDISTINCTCOUNT(‘Sales’[Product])
This DAX code estimates the count of unique values in the ‘Product’ column of the ‘Sales’ table. The ‘APPROXIMATEDISTINCTCOUNT’ function provides a faster estimate of distinct values compared to ‘DISTINCTCOUNT’.
AVERAGE(‘Sales’[SalesAmount])
Calculates the arithmetic mean of a column that contains numeric values.
AVERAGEA(‘Sales’[SalesAmount])
The AVERAGEA function in DAX calculates the arithmetic mean (average) of a column, including text and logical values in the calculation. Text is considered as 0 and logical values are considered as 1 (TRUE) or 0 (FALSE).
- Treat all non-blank numeric values in SalesAmount as their numeric value.
- Treat all text values in SalesAmount as 0.
- Treat all TRUE logical values as 1, and FALSE as 0.
- Calculate the average of these values.
AVERAGEX(‘Sales’, [SalesAmount] * [Quantity])
The AVERAGEX function in DAX is an iterator that calculates the average (arithmetic mean) of an expression evaluated over a table. It’s different from AVERAGE because it allows for a much more dynamic calculation that can include not just the contents of a column, but also the result of a calculation based on multiple columns for each row.
COUNT(‘Sales’[CustomerID])
The COUNT function in DAX is used to count the number of rows in a column that contain non-blank values. It’s important to note that COUNT only works with numeric data and will not count text or other non-numeric values. If you need to count rows with non-numeric data, you would use COUNTA
COUNTA(‘Sales’[CustomerName])
The COUNTA function in DAX counts the number of non-empty values in a column, including numbers, text, or any other type of data. It does not count blank or null values.
COUNTAX(‘Sales’, [SalesAmount] > 100)
The COUNTAX function in DAX is used to count non-blank results when evaluating an expression over a table. Unlike COUNT and COUNTA, which operate directly on a single column, COUNTAX applies a given expression to each row of a table and then counts the number of times that expression evaluates to a non-blank result.
COUNTBLANK(‘Sales’[DiscountAmount])
The COUNTBLANK function in DAX is used to count the number of blank or null values in a specified column. This function is particularly useful for identifying how many entries in a column are missing or have not been recorded.
COUNTROWS(‘Sales’)
The COUNTROWS function in DAX is used to count the number of rows in a table or in a table expression. It’s a straightforward way to determine the total number of entries (or records) in a given table.
COUNTX(‘Sales’, [SalesAmount] > 100)
The COUNTX function in DAX is an iterator function that counts the number of rows in a table where an expression evaluates to a non-blank result. It’s particularly useful when you want to apply a condition to each row of a table and count the number of rows that meet this condition.
DISTINCTCOUNT(‘Sales’[Product])
The DISTINCTCOUNT function in DAX counts the number of unique values in a column. It’s commonly used to determine the cardinality of categorical data.
DISTINCTCOUNTNOBLANK(‘Sales’[Product])
The DISTINCTCOUNTNOBLANK function in DAX is similar to DISTINCTCOUNT but it excludes blank values from the count of unique values in a column.
MAX(‘Sales’[SalesAmount])
The MAX function in DAX identifies the largest numeric value in a column. It’s useful for finding the maximum value in a range of numbers.
MAXA(‘Sales’[OrderDate])
The MAXA function in DAX evaluates both numeric and non-numeric values (including text represented as numbers and logical values) to find the largest value in a column.
MAXX(‘Sales’, [SalesAmount] * [Quantity])
The MAXX function in DAX is an iterator that evaluates an expression for each row in a table and returns the largest result. It allows for complex calculations that can involve multiple columns.
MIN(‘Sales’[SalesAmount])
The MIN function in DAX finds the smallest numeric value in a column. It is typically used to identify the minimum value in a dataset.
MINA(‘Sales’[OrderDate])
The MINA function in DAX works like MAXA but returns the smallest value in a column, considering all types of values including text and logicals.
MINX(‘Sales’, [SalesAmount] * [Quantity])
The MINX function in DAX evaluates an expression for each row in a table and returns the smallest result. It is an iterator that can handle complex row-by-row calculations.
PRODUCT(‘Sales’[Quantity])
The PRODUCT function in DAX multiplies all the numbers in a column and returns the total product. It’s useful for calculating cumulative product values.
PRODUCTX(‘Sales’, [SalesAmount] * [Quantity])
The PRODUCTX function in DAX is an iterator that calculates the product of an expression evaluated for each row in a table. This function can perform row-context-specific multiplications before aggregating the result.
SUM(‘Sales’[SalesAmount])
The SUM function in DAX adds all the numbers in a column, providing a total sum. It’s one of the most commonly used functions for basic aggregation.
SUMX(‘Sales’, [SalesAmount] * [Quantity])
The SUMX function in DAX sums up the results of an expression evaluated for each row in a table. It combines the flexibility of row-wise calculations with the simplicity of aggregation.
CALENDAR(DATE(2022,1,1), DATE(2022,12,31))
The CALENDAR function generates a table with a single column “Date” containing a contiguous set of dates between the specified start and end dates. In this example, it creates a calendar table for the year 2022.
CALENDARAUTO()
This function generates a calendar table with a single column “Date” containing a contiguous set of dates automatically determined by the data in your model. It doesn’t require explicit date range parameters.