Skip to content

Latest commit

 

History

History
148 lines (121 loc) · 5.2 KB

03.Scalar Functions.md

File metadata and controls

148 lines (121 loc) · 5.2 KB

Scalar Functions

Use case : Aggregating a column of values into a single number.

e.g. Average customer age, Maximum product profit, Sum of revenue, Count of orders, etc.

Function Syntax

FuntionName ( Argument 1, Argument 2, [Argument 3] )
  • Argument specified in square brackets [] are optional arguments.
  • Arguments specified without square brackets [] are mandatory arguments.
  • Few functions does not require any argument. e.g. NOW ( ), TODAY ( )
Aggregation Functions
SUMSum of all the values in a column.
AVERAGEMean of all the values in a column.
MINMinimum of all the values in a column.
MAXMaxmimum of all the values in a column.
COUNTCount of all the values in a column.
COUNTACount of all the non empty values in a column.
COUNTROWSCount of the number of rows in a column.
DISTINCTCOUNTCount of all the unique rows in a column.
// Better way to count the Distinct Rows.

Total Employee = 
COUNTROWS (
    VALUES (
        'Employee Lookup'
    )
)
Iterator Functions
SUMXSum of all the values in a column.
AVERAGEXMean of all the values in a column.
MINXMinimum of all the values in a column.
MAXXMaxmimum of all the values in a column.
COUNTXCount of all the values in a column.
// How the Code is written

Measure Name =
SUM ( 'Table Name'[Column Name] )

// How it's interpreted by DAX

Measure Name =
SUMX (
   'Table Name',
   'Table Name'[Column Name]
)

Converting fields into desired formats i.e. Text to Dates, Integers to Currency, etc.

Rounding Functions
INT(Number)Round a number to an Integer.
ROUND(Number, Digit)Round a number to a specific digit.
ROUNDUP(Number, Digit)Round a number up.
ROUNDDOWN(Number, Digit)Round a number down.
MROUND(Number, Multiple)Round a number to desired multiple.
TRUNC(Number)Remove decimals.
FIXED(Number)Round a number down and return as text.
CEILING(Number)Round up a number to nearest integer.
FLOOR(Number)Round down a number to nearest integer.
// Decimal Value  
INT(3.14567)          = 3
ROUND(3.14467, 2)     = 3.14
ROUNDUP(3.14467, 2)   = 3.15
ROUNDDOWN(3.14467, 2) = 3.14
FIXED(3.14467, 2)     = '3.14'

// Time Value
MROUND(9:34:15 AM, "0.15")   = 9:30:00 AM  -- Minute Round.
FLOOR(9:34:15 AM, "0.15")    = 9:30:00 AM  -- Rounds the minute component down to nearest multiple.
CEILING(9:34:15 AM, "0.15")  = 9:45:00 AM  -- Rounds the minute component up to nearest multiple.

Evaluating logical tests and returns value TRUE or FALSE

Logical Functions
IFAdd IF ELSE Condition.
ANDTRUE only if both are TRUE.
ORFALSE only if both are FALSE.
NOTCondition is NOT True.
SWITCHAdd Multiple Case with conditions.
COALESCEReturns non blank evaluations ( IF + ISBLANK )
// Returns sum of all non blank values in a column.

COALESCE (
      SUM ( 
          'Sales'[Quantity Sold],
      ),
      0
)

Check the value or data type of all the value or instances and returns TRUE or FALSE

e.g. Check whether all the rows of the column are text or numeric or is there any blank row.

Information Functions
ISBLANKCheck whether a value is blank.
ISERRORCheck whether a value is an error.
ISLOGICALCheck whether a value is a logical value.
ISNUMBERCheck whether a value is a number.
ISNONTEXTCheck whether a value is not a text.
ISTEXTCheck whether a value is text.

Evaluate the value to it's correct data type ot format.

Conversion Functions
CURRENCY(Value)Evaluate and return as a currency data type.
FORMAT(Value, Format)Convert a value to text in specified format.
DATE(Year, Month, Day)Return the specified date in datetime format.
TIME(Hour, Minute, Second)Return the specified time in datetime format.
DATEVALUE(DateText)Convert a date in a text.
VALUE(Text)Convert a text format date into a number.
Date Format (yyyy-mm-dd) =
FORMAT (
    "Calendar"[Date],
    "yyyy-mm-dd"
)