Logical functions perform basic logical operations on input data obtained from various data-sources.
In the sample below are listed all the supported logical functions:
equal, not-equal, greater-or-equal, greater, less, less-or-equal, and, or.
Examples:
1. The following sample illustrates the use of the equal, not-equal, greater and less functions.
This functions compare the first input parameter (op1) with the second input parameter (op2). The output is a Boolean value ("true" or "false").
The output displays the departments in which every employee worked, the hours worked and compares them with the number "300". For each function, the function will return "true" if the condition is satisfied; otherwise, "false".
Note:
• | The above example is part of the LogicalFuncitons1.dax document, located in the Samples/Job Samples folder. |
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns:root xmlns:ns="http://www.tempuri.org/XML">
<ns:hist department="Accounting" hours-worked="300" equals-300="true" not-equals-300="false" greater-than-300="false" less-than-300="false"/>
<ns:hist department="Sales" hours-worked="500" equals-300="false" not-equals-300="true" greater-than-300="true" less-than-300="false"/>
<ns:hist department="Accounting" hours-worked="1000" equals-300="false" not-equals-300="true" greater-than-300="true" less-than-300="false"/>
<ns:hist department="Sales" hours-worked="8000" equals-300="false" not-equals-300="true" greater-than-300="true" less-than-300="false"/>
<ns:hist department="Development" hours-worked="3000" equals-300="false" not-equals-300="true" greater-than-300="true" less-than-300="false"/>
<ns:hist department="Development" hours-worked="5000" equals-300="false" not-equals-300="true" greater-than-300="true" less-than-300="false"/>
<ns:hist department="Accounting" hours-worked="100" equals-300="false" not-equals-300="true" greater-than-300="false" less-than-300="true"/>
</ns:root>
2. The following example illustrates the use of the and and or functions.
These functions have two input parameters named op1 and op2 that must be Boolean values. These values are evaluated using the corresponding logical function. The output is a Boolean value as well.
The "and" function is used to check if the average number of hours worked is greater than or equal to 2500 and less than or equal to 2600. In that case it returns "true", otherwise it returns "false".
The "or" function is used to check if the average number of hours worked is greater than or equal to 2500 or less than or equal to 2600. In that case it returns "true", otherwise it returns "false".
Note:
• | The above example is part of the LogicalFunctions2.dax document, located in the Samples/Job Samples folder. |
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns:root average-hours-worked="2557" between-2500-and-2600="true" not-between-2500-and-2600="true" xmlns:ns="http://www.tempuri.org/XML"/>