Introduction Logical functions in power bi
Logical functions allow us to introduce decision making, these functions are used to check whether the condition is true or false and are also used to combine multiple conditions together.
Logical function is one the most useful expression of DAX in Power BI. So, here in this article you will learn about ‘Logical’ functions and how to use them.
I am going to explain some inportant types of logical functions, so let’s start.
IF
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE.
Syntax- IF(LogicalTest, ResultIfTrue, [ResultIfFalse])
LogicalTest- Any expression that can be evaluated to TRUE or FALSE
ResultIfTrue – It will be returned if logical test is TRUE.
ResultIfFalse-If logical test is FALSE then it will be returned.
Ex: I have use This condition
Input:
Measure = IF(8>4,”8 is greater than 4″,”8 less than 4″)
Out put:
AND
Check whether all arguments are TRUE, and returns TRUE if all arguments are TRUE.
Syntax- AND(logical1, Logical2)
Logical1- The Logical value that you want to check.
Logical2- This is also a logical value that you want to check.
Ex. I have use This below conditions
Input:
output:
Input:
output:
OR
Returns TRUE if any of the argumenta are TRUE, and returns false if all arguments are FALSE.
Syntax- OR (Logical1, Logical2)
Logical1 – The logic value that you want to check.
Logical2 – The logic value that you want to check.
Ex : I have use This condition
Input :
Output :
TRUE
Return the logical value TRUE always.
Syntax-TRUE()
Ex:
Input :
measure = IF(20<30,TRUE(),FALSE())
Output:
True statement
False
COALESCE
Returns the first argument that does not evaluate to BLANK. If all arguments evaluate to BLANK, BLANK is returned.
Syntax- COALESCE(Value1, Value2[,Value3……])
Value1- Any expression that returns the scalar value.
Ex :
Input:
Output:
IFERROR
Returns value_if_error if the first expression is an error and the value of the expression itself otherwise.
Syntax- IFERROR(Value, ValueIfError)
Value- Any expression or value
ValueIfError- Any expression or value
Ex:
Input:
Output:
In the below example the first value will give an error so, this function will return the second value.
For any Help or Queries Contact us on info@crmonce.com or +91 – 9014146800.
https://www.crmonce.com/add-index-column-in-power-bi-using-power-query-editor/