DAX FORMULAS
SUM
Purpose: Adds up all the numbers in a column.
Example: Total Sales = SUM(Sales[Amount])
AVERAGE
Purpose: Calculates the average of a column.
Example: Average Sales = AVERAGE(Sales[Amount])
COUNT / COUNTA
Purpose: Counts the number of rows in a column (COUNT) or counts the number of
non-empty values (COUNTA).
Example: Total Orders = COUNT(Orders[OrderID])
Example: Total Customers = COUNTA(Customers[CustomerID])
DISTINCTCOUNT
Purpose: Counts the number of unique values in a column.
Example:
Unique Customers = DISTINCTCOUNT(Sales[CustomerID])
MAX / MIN
Purpose: Finds the maximum or minimum value in a column.
Example: Max Sale = MAX(Sales[Amount])
Example: Min Sale = MIN(Sales[Amount])
CALCULATE
Purpose: Evaluates an expression in a modified filter context.
Example:
Total Sales West Region = CALCULATE(SUM(Sales[Amount]), Sales[Region] = "West")
IF
Purpose: Performs a logical test and returns one value if true, and another if false.
Example:
High Sales = IF(Sales[Amount] > 1000, "High", "Low")
SWITCH
Purpose: Evaluates an expression against a list of values and returns the corresponding
result.
Example:
Rating = SWITCH( TRUE(),
Sales[Amount] > 1000, "High",
Sales[Amount] > 500, "Medium",
"Low"
)
RELATED
Purpose: Retrieves a related value from another table.
Example:
Product Category = RELATED(Products[Category])
DATEADD
Purpose: Shifts dates by a specified interval.
Example:
Sales Last Year = CALCULATE(SUM(Sales[Amount]), DATEADD(Sales[Date], -1, YEAR))
SUMX
Purpose: Evaluates an expression for each row of a table and then sums the results.
Example:
Total Sales = SUMX(Sales, Sales[Quantity] * Sales[Price])
ALL
Purpose: Removes all filters from a table or column.
Example:
All Sales = CALCULATE(SUM(Sales[Amount]), ALL(Sales[Region]))
ALLEXCEPT
Purpose: Removes all filters except those on the specified columns.
Example:
Total Sales Excluding Region Filter = CALCULATE(SUM(Sales[Amount]),
ALLEXCEPT(Sales, Sales[Product]))
VALUES
Purpose: Returns a one-column table with distinct values from a specified column.
Example:
Distinct Regions = VALUES(Sales[Region])
EARLIER
Purpose: Refers to an earlier row context.
Example:
Rank = RANKX( ALL(Sales), CALCULATE(SUM(Sales[Amount])),,DESC,DENSE)
DIVIDE
Purpose: Performs division and handles divide-by-zero errors.
Example:
Sales per Order = DIVIDE(SUM(Sales[Amount]), COUNT(Sales[OrderID]))
FORMAT
Purpose: Formats a value as a string according to a specified format.
Example:
Formatted Date = FORMAT(Sales[Date], "MM/DD/YYYY")
LOOKUPVALUE
Purpose: Returns the value in a row that meets all specified criteria.
Example:
Customer Segment = LOOKUPVALUE(Customers[Segment], Customers[CustomerID],
Sales[CustomerID])
FILTER
Purpose: Returns a table that represents a subset of another table or expression.
Example:
Top Sales = CALCULATE(SUM(Sales[Amount]), FILTER(Sales, Sales[Amount] > 1000))
CROSSFILTER
Purpose: Specifies the cross-filtering direction to be used in a calculation for a
relationship.
Example:
CrossFiltered Sales = CALCULATE( SUM(Sales[Amount]),
CROSSFILTER(Sales[CustomerID], Customers[CustomerID], BOTH)
)
ALLSELECTED
Purpose: Removes context filters from columns and rows in the current query while
keeping explicit filters.
Example:
All Selected Sales = CALCULATE(SUM(Sales[Amount]), ALLSELECTED(Sales))
ADDCOLUMNS
Purpose: Adds calculated columns to a table.
Example:
Sales with Discount = ADDCOLUMNS(Sales, "Discounted Amount", Sales[Amount] *
0.9)
RANKX
Purpose: Returns the rank of a number in a list of numbers for each row in the table.
Example:
Sales Rank = RANKX(ALL(Sales), Sales[Amount], , DESC, DENSE)
GENERATE
Purpose: Returns a table with each row from the first table and its associated rows from
the second table.
Example:
Sales Combinations = GENERATE(Products, Sales)
GROUPBY
Purpose: Returns a table grouped by specified columns.
Example:
Grouped Sales = GROUPBY (Sales, Sales[Region], "Total Sales",
SUMX(CURRENTGROUP(), Sales[Amount])
)
SUMMARIZE
Purpose: Returns a summary table for the requested totals over a set of groups.
Example:
Sales Summary = SUMMARIZE( Sales, Sales[Region], "Total Sales",
SUM(Sales[Amount]))
UNION
Purpose: Combines two tables with the same structure.
Example:
Combined Table = UNION( Sales2019, Sales2020)
INTERSECT
Purpose: Returns the rows that appear in both tables.
Example:
Common Sales = INTERSECT( Sales2019,Sales2020)
EXCEPT
Purpose: Returns the rows of one table which do not appear in another table.
Example:
Unique Sales = EXCEPT( Sales2019, Sales2020 )
LOOKUPVALUE
Purpose: Retrieves the value of a column from a related table.
Example:
Customer Country = LOOKUPVALUE(Customers[Country], Customers[CustomerID],
Sales[CustomerID])
CONCATENATEX
Purpose: Concatenates the result of an expression evaluated for each row of a table.
Example:
Product List = CONCATENATEX( Products, Products[Name], ", ")
DATEDIFF
Purpose: Calculates the difference between two dates.
Example: To find the number of days between the order date and the delivery date:
Delivery Time (Days) = DATEDIFF(Orders[OrderDate], Orders[DeliveryDate], DAY)
RELATEDTABLE
Purpose: Returns a table that is related to the current table through a relationship.
Example: To calculate the total sales for each product by summing up the related sales
records:
Total Product Sales = SUMX(RELATEDTABLE(Sales), Sales[Amount])