10 DAX Functions That I Regularly Use
10 DAX Functions That I Regularly Use
SUM / SUMX
SUM(<column>)
SUMX(<table>, <expression>)
Examples
SUM(Sales[Amount]) - Returns the sum of sales amount
SUMX ( Sales, Sales[Quantity] * Sales[Net Price] ) - Calculates total revenue by
multiplying Quantity and Net Price for each row in the Sales table and summing the
results
2
DIVIDE
DIVIDE ( <Numerator>, <Denominator> [, <AlternateResult>] )
Example
DIVIDE(SUM(Sales[Profit]), SUM(Sales[Revenue]), 0) - Calculates profit margin by
dividing total profit by total revenue, using DIVIDE to avoid errors if revenue is zero,
returning 0 instead.
3
COUNT / DISTINCTCOUNT
COUNT ( <ColumnName> )
DISTINCTCOUNT ( <ColumnName> )
Examples
COUNT(Sales[Order ID]) - Counts the total number of orders in the Sales table.
DISTINCTCOUNT(Sales[Customer ID]) - Counts the unique number of customers in the
Sales table by identifying each unique Customer ID. This helps track the number of
unique buyers.
4
CALCULATE
CALCULATE ( <Expression> [, <Filter> [, <Filter> [, … ] ] ] )
Example
CALCULATE(SUM(Sales[Amount]), Products[Category] = "Electronics") - Calculates the
total sales amount specifically for products in the "Electronics" category.
5
IF / SWITCH
IF ( <LogicalTest>, <ResultIfTrue> [, <ResultIfFalse>] )
SWITCH ( <Expression>, <Value>, <Result> [, <Value>,
<Result> [, … ] ] [, <Else>] )
These logical functions let you implement business logic directly in your
measures, enabling conditional calculations or formatting, data labeling,
or complex grouping.
IF handles simple conditions, while SWITCH is a more flexible alternative
for handling multiple conditions.
Examples
IF(Sales[Amount] > 1000, "High Value", "Standard") - Classifies orders based on their
amount
SWITCH( TRUE(), Sales[Amount] > 10000, "Excellent", Sales[Amount] > 5000,
"Good", Sales[Amount] > 1000, "Average", "Below Average") - Assigns
performance levels based on sales
6
AND (&&) / OR(||)
AND ( <Logical1>, <Logical2> ) / <Logical1> && <Logical2>…
OR ( <Logical1>, <Logical2> ) / <Logical1> || <Logical2> …
Examples
Using AND function: IF( AND(Products[Stock] < 20, Products[Demand] > 500), "Top
Priority", "Normal" )
Using && operator: IF( Products[Stock] < 20 && Products[Demand] > 500, "Top Priority",
"Normal" )
- Flags products as "Top Priority" if stock is low and demand is high
7
DATEADD / SAMEPERIODLASTYEAR
DATEADD ( <Dates>, <NumberOfIntervals>, <Interval> )
SAMEPERIODLASTYEAR ( <Dates> )
Examples
CALCULATE( SUM(Sales[Amount]), DATEADD(Calendar[Date], -1, MONTH)) -
Calculates sales from the previous month
Example:
CALCULATE( [Sales Amount], KEEPFILTERS(Products[Color] = “Blue") ) - In this
example, KEEPFILTERS ensures that the “Blue" filter is added without replacing any
other active filters on Products[Color]. This maintains the existing color context in the
report while still filtering for blue products.
9
SELECTEDVALUE
SELECTEDVALUE ( <ColumnName> [, <AlternateResult>] )
Example
SELECTEDVALUE(Regions[Region], "All Regions") - Displays the selected region
dynamically
10
USERELATIONSHIP
Example
CALCULATE(SUM(Sales[Amount]), USERELATIONSHIP(Sales[Ship Date], Calendar[Date]))
- USERELATIONSHIP activates the relationship between Sales[Ship Date] and
Calendar[Date] to calculate sales by shipment date. This relationship is usually inactive
because the active relationship is set to Order Date.
BONUS
CALENDAR
CALENDAR ( <StartDate>, <EndDate> )
If your data model doesn’t include a built-in date table, you can create one
using the CALENDAR function in DAX. A date table is essential for time
intelligence calculations and ensures consistent date filtering across your
report.
CALENDAR generates a table with a continuous range of dates (static or
dynamic) that you define, making it easy to create a comprehensive date
table.
Example
CALENDAR(DATE(2020, 1, 1), DATE(2023, 12, 31)) - Creates a date table that spans from
January 1, 2020, to December 31, 2023
What about you?