Open In App

Power BI- DAX IF Functions

Last Updated : 23 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

To generate formulas and expressions in Excel data models for Power BI, Analysis Services, and Power Pivot, Data Analysis Expressions (DAX), a group of functions and operators, can be combined. Data Analysis Expression is a feature of the Power BI toolset that enables business analysts to maximize the value of their datasets. These expressions make the process of creating reports faster and more enjoyable for the data analyst.

DAX IF Functions

Logical IF functions, which are used to combine many conditions and decide if a condition is true or not, enable the introduction of decision-making. Logical functions provide details about the values or sets in an expression when they are applied to it. Let’s validate these functions on a sample library supplies dataset. It can be seen as follows-

Dataset

Dataset

Apply the following queries by adding a New column in the model.

New-column

 

DAX IF

Validates a condition and, if TRUE, returns one value; else, it returns another.

Syntax: IF(<logical_test>, <value_if_true>[, <>])

  • logical_test: Anything that may be evaluated to either TRUE or FALSE.
  • value_if_true: The result that is returned when the logical test returns TRUE.
  • value_if_false: The value that is returned if the logical test returns FALSE (optional). BLANK is returned if it is left out.

In the following example, we are checking if the client is Delhiite or not, based on the name of the Client State.

Example: Column = IF(‘SLS Order Detials_Master'[Client State]= “New Delhi”, “Resident”, “Non-resident”)

The column gets added to the dataset as shown below,

dax-if-function-example

 

DAX IF.EAGER

Validates a condition and, if TRUE, returns one value; else, it returns another. The execution plan is eager, and regardless of the condition expression, it always performs the branch expressions.

Syntax: IF.EAGER(<logical_test>, <value_if_true>[, <value_if_false>])

  • logical_test: Anything that may be evaluated to either TRUE or FALSE.
  • value_if_true: The result that is returned when the logical test returns TRUE.
  • value_if_false: The value that is returned if the logical test returns FALSE (optional). BLANK is returned if it is left out.

In the following example, we are checking if the client is Delhiite or not, based on the Client’s Pin code.

Example: Column1 = IF.EAGER(‘SLS Order Detials_Master'[Client Pin Code]= “110003”, “Resident”, “Non-resident”)

The column gets added to the dataset as shown below,

If.Eager-function-example

 

DAX IFERROR

DAX IFERROR returns the outcome of the expression itself unless the expression returns an error, in which case it returns a specified value.

Syntax: IFERROR(value, value_if_error)

  • value: Any term or value.
  • value_if_error: Any term or value.

Example: Column2 = IFERROR(345/0,345) 

The column gets added to the dataset as shown below,

IfError-function-example

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads