DAX - Statistical Functions Flashcards
What do statistical functions do?
- Calculate values related to statistical distibutions and probability
- Calculations and comparisons that reveal meaningful information about the data. Such as:
Trends
Patterns
Relationships
Common statistical functions
- Average
- Median
- Count
- Distinct(Count)
- Min
- Max
How does MAX work?
Returns the largest numeric value or largest string in a column. Ignores logical values.
NOTE: As the MAX function ignores logical values, TRUE and FALSE in the table are interpreted as texts. Texts are considered “larger” than numbers in DAX alphabetically, so the largest value in the column is TRUE, as it’s the last in alphabetical order.
How does MIN work?
Returns the smallest numeric value or shortest string in a column. Ignores logical values.
NOTE: As the MIN function also ignores logical values, same as the MAX function, the sequence of blank values, numbers and texts is followed in ascending order. A blank value in the sample column is considered as the
minimum value.
How does the average function work?
- It sums up all the numbers in a dataset
- Divides the result by the total count of numbers
How does the median function work?
- Sorts the numbers in asc order
- Selects the middle number
- If there are two middle numbers, take the average of the two as the median.
For example, if the ItemPrice column in the Sales table contained 2 values,
the formula would be calculated as:
(160 + 180) / 2 = 170
Example of AVERAGEX function
AVERAGEX (Sales, Sales[Freight] + Sales[TaxAmt])
In this example:
1. Sales[Freight] + Sales[TaxAmt] is calculated for each row
2. Then the sums are averaged
How does AVERAGEX work?
AVERAGEX(Table, Sales[Quantity] * Sales[Price])
It goes row by row and calculates the Sales Amount (quantity x price). Then it calculates an average of Sales Amount amongst all the rows that were calculated
For example, if the ItemPrice column and the QuantitySold column each contained 8 values, the formula would be calculated as:
((120 * 5) + (140 * 7) + (180 * 3) + (130 * 6) + (200 * 4) + (240 * 9) + (160 * 2) + (190 * 8)) / 8 = 962.50
What does AVERAGEA do?
AVERAGEA([ColumnName)
Calculates the average of non blank cells in a column
NOTE
-Values that evaluate to TRUE count as 1.
-Values that evaluate to FALSE count as 0 (zero).
-Values that contain non-numeric text count as 0 (zero).
-Empty text (“”) counts as 0 (zero).
For example, if the ItemPrice_withText column contained 8 values, with non-numeric values being counted as 0, the formula would be calculated as:
(120 + 1 + 0 + 130 + 180 + 0 + 280 + 1) / 8 = 89
Is the Median or Average less affected by outliers and extreme values?
Median
It is therefore useful for datasets with skewed distributions
What is returned if there are no rows to count using COUNT or DISTINCTCOUNT
(blank)
What does count do?
Counts the total number of rows, containing any or no value
What does COUNTBLANK do?
Counts the number of blank or empty rows in a column
How does COUNTA work?
It counts the number of cells in a column that are not blank
How does COUNTAX work?
Goes row by row and and counts rows where the specified expression results in a non-blank result.