dax formulas
Calculated measure using SUM to aggregate a column
Total Sales = SUM('TableName'[SalesAmount])
Total Cost = SUM('TableName'[Cost])
Calculated measure using two previously created calculated
measures to determine profit
Profit = [Total Sales] - [Total Cost]
Calculated measure using two previously created calculated
measures to determine profit margin, the DIVIDE
function is used to perform the division
Profit Margin = DIVIDE( [Profit], [Total Sales])
Calculated measure that returns a count of all rows in a table,
ultimately, many times this simple calculation is used
to return transaction counts.
Transactions = COUNTROWS('Table')
Returns the total rows in a related table. For example, total
transactions by Product.
Transactions = COUNTROWS(RELATEDTABLE('TABLE'))
Calculates Total Sales for all days in the current month up to
the maximum day in the selection.
MTD Sales = TOTALMTD( [Total Sales], 'DateTable'[DateColumn] )
MTD Sales (Direct Query) = MTD Sales =
CALCULATE (
[Total Sales],
FILTER (
ALL ( 'DateTable' ),
'DateTable'[DateYear] = MAX ( 'DateTable'[DateYear] ) &&
'DateTable'[DateMonth] = MAX ( 'DateTable'[DateMonth] ) &&
'DateTable'[Date] <= MAX ( 'DateTable'[Date] )
)
)
Calculates Total Sales for all days in the year up to the maximum
day in the selection.
YTD Sales = TOTALYTD( [Total Sales], 'DateTable'[DateColumn] )
YTD Sales (Direct Query) =
CALCULATE (
[Total Sales],
FILTER (
ALL ( 'DateTable' ),
'DateTable'[DateYear] = MAX ( 'DateTable'[DateYear] ) &&
'DateTable'[Date] <= MAX ( 'DateTable'[Date] )
)
)
This calculation uses an optional third parameter specifying
the fiscal year end date.
YTD Sales (Fiscal Calendar) = TOTALYTD(
[Total Sales],
'DateTable'[DateColumn],
"05/31"
)