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.
DATE(2022, 2, 15)
The DATE function returns a datetime value for the specified year, month, and day. In this example, it creates a datetime value for February 15, 2022.
DATEDIFF(‘Sales’[OrderDate], ‘Sales’[ShipDate], DAY)
This function calculates the number of days between two dates. In this example, it calculates the number of days between the ‘OrderDate’ and ‘ShipDate’ columns in the ‘Sales’ table. The third argument specifies the interval as “DAY”.
DATEVALUE(“2022-01-31”)
The DATEVALUE function converts a date in text format to a datetime value. In this example, it converts the text “2022-01-31” to a datetime value.
DAY(‘Sales’[OrderDate])
The DAY function returns the day of the month (a number from 1 to 31) for a given date. In this example, it returns the day of the month for the ‘OrderDate’ column in the ‘Sales’ table.
EDATE(‘Sales’[StartDate], 3)
The EDATE function returns a date that is a specified number of months before or after a given start date. In this example, it calculates a date that is 3 months after the ‘StartDate’ column in the ‘Sales’ table.
EOMONTH(TODAY(), -1)
The EOMONTH function returns the last day of the month before or after a specified number of months from a given date. In this example, it calculates the last day of the month one month before today’s date.
HOUR(‘Sales’[OrderTime])
The HOUR function returns the hour (as a number from 0 to 23) for a given datetime value. In this example, it returns the hour of the ‘OrderTime’ column in the ‘Sales’ table.
MINUTE(‘Sales’[StartTime])
The MINUTE function returns the minute (a number from 0 to 59) for a given datetime value. In this example, it returns the minute of the ‘StartTime’ column in the ‘Sales’ table.
MONTH(‘Sales’[InvoiceDate])
The MONTH function returns the month (a number from 1 to 12) for a given date. In this example, it returns the month of the ‘InvoiceDate’ column in the ‘Sales’ table.
NETWORKDAYS(‘Calendar’[Date], TODAY())
The NETWORKDAYS function calculates the number of whole workdays between two dates, considering weekends and optionally specified holidays. In this example, it calculates the network days between a date in the ‘Calendar’ table and today’s date.
NOW()
The NOW function returns the current date and time in datetime format. In this example, it returns the current date and time.
QUARTER(‘Sales’[OrderDate])
The QUARTER function returns the quarter of the year (a number from 1 to 4) for a given date. In this example, it returns the quarter of the ‘OrderDate’ column in the ‘Sales’ table.
SECOND(‘Sales’[EndTime])
The SECOND function returns the seconds (a number from 0 to 59) of a given time value. In this example, it returns the seconds of the ‘EndTime’ column in the ‘Sales’ table.
TIME(15, 30, 0)
The TIME function converts hours, minutes, and seconds given as numbers into a time in datetime format. In this example, it creates a time value for 3:30 PM.
TIMEVALUE(“09:45:00 AM”)
The TIMEVALUE function converts a time in text format to a time in datetime format. In this example, it converts the text “09:45:00 AM” to a time value.
TODAY()
The TODAY function returns the current date. In this example, it returns today’s date.
UTCNOW()
The UTCNOW function returns the current UTC (Coordinated Universal Time) date and time. In this example, it returns the current UTC date and time.
UTCTODAY()
The UTCTODAY function returns the current UTC date. In this example, it returns the current UTC date.
WEEKDAY(‘Calendar’[Date])
The WEEKDAY function returns a number from 1 to 7 identifying the day of the week for a given date. In this example, it returns the day of the week for a date in the ‘Calendar’ table.
WEEKNUM(‘Calendar’[Date], 2)
The WEEKNUM function returns the week number for a given date and year according to the specified return_type value. In this example, it calculates the week number for a date in the ‘Calendar’ table using return_type 2 (ISO week numbering).
YEAR(‘Sales’[OrderDate])
The YEAR function returns the year of a date as a four-digit integer in the range 1900-9999. In this example, it returns the year of the ‘OrderDate’ column in the ‘Sales’ table.
YEARFRAC(‘Sales’[StartDate], ‘Sales’[EndDate])
The YEARFRAC function calculates the fraction of the year represented by the number of whole days between two dates. In this example, it calculates the year fraction between the ‘StartDate’ and ‘EndDate’ columns in the ‘Sales’ table.
ALL(‘Sales’)
The ALL function returns all the rows in a table, ignoring any filters that might have been applied. In this example, it returns all rows in the ‘Sales’ table.
ALLCROSSFILTERED()
This function clears all filters that are applied to a table, removing any cross-filtering effects. It doesn’t require any specific arguments.
ALLEXCEPT(‘Sales’, ‘Sales’[ProductCategory])
The ALLEXCEPT function removes all context filters in the ‘Sales’ table except for the filters applied to the ‘ProductCategory’ column. It retains filters on that specified column.
ALLNOBLANKROW(‘Product’)
The ALLNOBLANKROW function returns all rows of a table except the blank row and disregards any context filters. In this example, it returns all distinct values of the ‘Product’ column except the blank row.
ALLSELECTED(‘Date’[Date])
The ALLSELECTED function removes context filters from columns and rows in the current query while retaining all other context filters or explicit filters. In this example, it removes filters from the ‘Date’ table’s ‘Date’ column.
CALCULATE(SUM(‘Sales’[SalesAmount]), ‘Product’[Category] = “Electronics”)
The CALCULATE function evaluates an expression in a modified filter context. In this example, it calculates the sum of ‘SalesAmount’ in the ‘Sales’ table while filtering the ‘Product’ table by the category “Electronics”.
CALCULATETABLE(‘Sales’, ‘Sales’[Quantity] > 5)
The CALCULATETABLE function evaluates a table expression in a modified filter context. In this example, it returns a new table consisting of rows from the ‘Sales’ table where the ‘Quantity’ is greater than 5.
EARLIER(‘Sales’[Product])
The EARLIER function returns the current value of the specified column in an outer evaluation pass of the mentioned column. In this example, it returns the ‘Product’ column value from the outer context.
EARLIEST(‘Sales’[OrderDate])
The EARLIEST function returns the current value of the specified column in an outer evaluation pass of the ‘OrderDate’ column. It is typically used in time intelligence calculations.
FILTER(‘Sales’, ‘Sales’[Quantity] > 10)
The FILTER function returns a table that represents a subset of another table or expression based on specified conditions. In this example, it filters the ‘Sales’ table to include only rows where the ‘Quantity’ is greater than 10.
INDEX(‘Products’, 3)
The INDEX function returns a row at an absolute position specified by the position parameter within the specified table. In this example, it returns the third row from the ‘Products’ table.
KEEPFILTERS(CALCULATE(SUM(‘Sales’[SalesAmount]), ‘Product’[Category] = “Electronics”))
The KEEPFILTERS function modifies how filters are applied while evaluating a CALCULATE or CALCULATETABLE function. It retains the existing filters when calculating the sum of ‘SalesAmount’ while filtering the ‘Product’ table by the category “Electronics”.
LOOKUPVALUE(‘Sales’[ProductName], ‘Sales’[ProductID], 101)
The LOOKUPVALUE function returns the value for the row that meets all criteria specified by search conditions. In this example, it looks up the ‘ProductName’ where the ‘ProductID’ is 101 in the ‘Sales’ table.
RANKX(‘Sales’, [SalesAmount], , DESC)
In window functions, the MATCHBY parameter defines the columns used to determine how to match data and identify the current row. This example uses ‘RANKX’ and defines the sorting and ranking order for ‘SalesAmount’.
OFFSET(‘Sales’, 1)
The OFFSET function returns a single row positioned either before or after the current row within the same table, by a given offset. In this example, it returns the row that is 1 position after the current row in the ‘Sales’ table.
ORDERBY(‘Sales’, ‘Sales’[OrderDate], ASC)
In window functions, the ORDERBY function defines the columns that determine the sort order within each partition. This example orders the ‘Sales’ table by ‘OrderDate’ in ascending order.
PARTITIONBY(‘Sales’, ‘Sales’[Category])
In window functions, the PARTITIONBY function defines the columns used to partition a WINDOW function’s relation parameter. This example partitions the ‘Sales’ table by the ‘Category’ column.
RANKX(‘Sales’, [SalesAmount], , DESC)
In window functions, the RANK function returns the ranking of a row within the given interval. This example calculates the rank of each row in the ‘Sales’ table based on ‘SalesAmount’ in descending order.
REMOVEFILTERS(‘Product’, ‘Category’)
The REMOVEFILTERS function clears filters from the specified tables or columns. In this example, it removes filters from the ‘Product’ and ‘Category’ tables.
ROWNUMBER(‘Sales’, [SalesAmount], , DESC)
In window functions, the ROWNUMBER function returns the unique ranking of a row within the given interval. This example calculates a unique sequential number for each row in the ‘Sales’ table based on ‘SalesAmount’ in descending order.
SELECTEDVALUE(‘Product’[Category], “Default”)
The SELECTEDVALUE function returns the value when the context for the columnName has been filtered down to one distinct value only. Otherwise, it returns the alternateResult. In this example, it returns the selected ‘Category’ value from the ‘Product’ table or “Default” if multiple values exist.
WINDOW(MAX(‘Sales’[OrderDate]), -1, 1)
The WINDOW function returns multiple rows positioned within the given interval. In this example, it returns rows within a window defined by the maximum ‘OrderDate’ value, one row before, and one row after that maximum value from the ‘Sales’ table.
COLUMNSTATISTICS(‘Sales’)
The COLUMNSTATISTICS function returns a table of statistics regarding every column in the ‘Sales’ table (or any specified table), providing insights into column characteristics like minimum, maximum, and average values.
CONTAINS(‘Products’[Category], “Electronics”)
The CONTAINS function checks if the ‘Category’ column in the ‘Products’ table contains the value “Electronics” and returns TRUE if it does, or FALSE if it doesn’t.
CONTAINSROW(‘Customers’, ‘Customers’[CustomerID], 101)
The CONTAINSROW function checks if a row of values exists in the ‘Customers’ table (based on the ‘CustomerID’ column) with a value of 101 and returns TRUE if it does, otherwise, it returns FALSE.
CONTAINSSTRING(‘TextData’[Description], “important”)
The CONTAINSSTRING function checks if the ‘Description’ column in the ‘TextData’ table contains the string “important” and returns TRUE if it does, or FALSE if it doesn’t.
CONTAINSSTRINGEXACT(‘TextData’[Title], “Exact Match”)
The CONTAINSSTRINGEXACT function checks if the ‘Title’ column in the ‘TextData’ table contains the exact string “Exact Match” and returns TRUE if it’s an exact match, otherwise, it returns FALSE.
CUSTOMDATA()
The CUSTOMDATA function returns the content of the CustomData property in the connection string, providing custom data or metadata related to the data source.
HASONEFILTER(‘Product’[Category])
The HASONEFILTER function returns TRUE when there is only one directly filtered value on the ‘Category’ column in the ‘Product’ table, indicating single-value filtering.
HASONEVALUE(‘Customer’[CustomerID])
The HASONEVALUE function returns TRUE when the context for ‘CustomerID’ has been filtered down to one distinct value only in the ‘Customer’ table. Otherwise, it returns FALSE.
ISAFTER(‘Date’[Date], DATE(2022, 1, 1))
The ISAFTER function emulates the behavior of a Start At clause and returns true for a row where the ‘Date’ column is on or after January 1, 2022.
ISBLANK(‘Sales’[Revenue])
The ISBLANK function checks whether the ‘Revenue’ column in the ‘Sales’ table is blank (no revenue recorded) and returns TRUE or FALSE accordingly.
ISCROSSFILTERED(‘Order’[ProductID])
The ISCROSSFILTERED function returns TRUE when the ‘ProductID’ column in the ‘Order’ table or another related table is being filtered directly, indicating cross-filtering.
ISEMPTY(‘EmptyTable’)
The ISEMPTY function checks if the ‘EmptyTable’ is empty (contains no rows) and returns TRUE if it’s empty, otherwise, it returns FALSE.
ISERROR([SalesAmount])
Checks if the value in the ‘SalesAmount’ column is an error. If it is, it returns TRUE; otherwise, it returns FALSE.
ISEVEN([OrderQuantity])
Determines if the ‘OrderQuantity’ is an even number and returns TRUE if it is, or FALSE if it’s odd.
ISFILTERED(‘Date’[Year])
Verifies if the ‘Year’ column in the ‘Date’ table is currently filtered. Returns TRUE if filtered, FALSE if not.
ISINSCOPE(‘Product’[Category])
Checks if the ‘Category’ column in the ‘Product’ table is currently in scope. Returns TRUE if it is, FALSE if not.
ISLOGICAL([IsCompleted])
Determines if the value in the ‘IsCompleted’ column is a logical value (TRUE or FALSE). Returns TRUE for logical values, otherwise FALSE.
ISNONTEXT([ProductName])
Checks if the ‘ProductName’ column contains non-text values (blank cells are considered non-text). Returns TRUE if non-text, FALSE if text.
ISNUMBER([UnitPrice])
Determines if the values in the ‘UnitPrice’ column are numbers. Returns TRUE for numbers, FALSE for non-numeric values.
ISODD([InvoiceNumber])
Checks if the ‘InvoiceNumber’ is an odd number and returns TRUE if it is, or FALSE if it’s even.
ISONORAFTER([TransactionDate], “2022-01-01”)
Emulates the behavior of a Start At clause and returns TRUE for rows with ‘TransactionDate’ after January 1, 2022.
ISSELECTEDMEASURE([Total Sales], [Total Profit], [Revenue])
Checks if one of the specified measures is selected in the current context. Returns TRUE if selected, otherwise FALSE.
ISSUBTOTAL([IsSubtotal], [Category])
Creates a column in a SUMMARIZE expression that returns TRUE if the row contains subtotal values for the ‘Category’ column, otherwise FALSE.
ISTEXT([CustomerComments])
Determines if the values in the ‘CustomerComments’ column are text. Returns TRUE for text values, FALSE for non-text.
NONVISUAL(‘Region’[Region])
Marks a value filter in a SUMMARIZECOLUMNS expression as non-visual for the ‘Region’ column.
SELECTEDMEASURE()
Returns the name of the currently selected measure in the context.
SELECTEDMEASUREFORMATSTRING()
Returns the format string of the currently selected measure in the context.
SELECTEDMEASURENAME()
Returns the name of the currently selected measure in the context.
USERCULTURE()
Returns the locale for the current user.
USERNAME()
Returns the domain name and username from the credentials given to the system at connection time.
USEROBJECTID()
Returns the current user’s Object ID or SID.
USERPRINCIPALNAME()
Returns the user principal name.
AND([IsCompleted], [IsApproved])
Checks whether both ‘IsCompleted’ and ‘IsApproved’ columns are TRUE, and returns TRUE if both are TRUE; otherwise, returns FALSE.
BITAND(5, 3)
Performs a bitwise ‘AND’ operation on the binary representations of 5 and 3 and returns the result.