Power BI DAX Filter If [With Real Examples]

Are you interested in learning how to filter the table data based on the Power BI DAX IF condition? Then this Microsoft Power BI tutorial will guide you to filter the data using the Power BI DAX Filter function in Power BI.

Recently I was working with the Power BI report, where I needed to filter the data using the Power Bi Dax filter if function.

Also, we will see below more examples related to the Power BI Dax filter if functions:

  1. How to filter values with multiple conditions using Power BI Dax Filter if
  2. Working with Power BI DAX filter true false
  3. How to work with Power BI DAX filter if contains text
  4. How to check if no filter is selected Power BI DAX
  5. Working with Power BI DAX if statement with filter
  6. What is Power BI DAX if filter selected

Power BI DAX filter multiple conditions

Let us see how we can use filter multiple conditions using the Power Bi Dax filter function in Power Bi.

In this example, we use the sales table to apply multiple filters to obtain the desired sum value of sales based on the filter condition.

  • Open the Power Bi desktop and load the table data into it, From the ribbon click on the new measure option and apply the below formula:
Multiple filter conditions = CALCULATE(
SUM('Sales_Table'[Sales]),
FILTER('Sales_Table',Sales_Table[Product Name] in {"Laptop", "Desktop"
}),
FILTER('Sales_Table','Sales_Table'[Customer Location] in {"Marryland", "Florida"})
)

Where,

  1. Multiple filter conditions = Measure name
  2. Sales Table = Table name
  3. Sales, Product Name, Customer Location = Column names
  • Now, in the report section, select the table and card visual from the visualizations.
  • In the table visual, drag and drop the Product name, Customer location, and sales value from the field pane, and in the visual card drag and drop the created Measure value.
  • The screenshot below shows that the card visually displays the filtered value based on the multiple filters condition applied.
Power BI DAX filter multiple conditions
Power BI DAX filter multiple conditions

This is how to use filter conditions using the Power Bi Dax filter function in Power Bi.

Also Read: Power BI Dax Filter [With 15+ Examples]

Power BI DAX filter true false

Let us see how we can use the filter function to check the true or false value based on the condition in Power Bi.

In this example, we use the Vehicles table data to apply filters to obtain the result value as true or false based on the filter condition.

  • Open the Power Bi desktop and load the table data into it, From the ribbon click on the new measure option and apply the below formula:
SUM Value = 
VAR total =
    CALCULATE(
        SUM(Cars[Price]),
        FILTER(ALLSELECTED(Cars),
            IF(
                CONTAINSSTRING(LOWER(Cars[Car Names]),"Ford") ||
                CONTAINSSTRING(LOWER(Cars[Car Names]),"Audi"), "True", "False"
            )
        )
    )
RETURN
 IF ( total > 1000000, "True", "False" )

Where,

  1. SUM Value = Measure name
  2. total = Variable name
  3. Cars = Table name
  4. Car Names, Price = Column name
  • Now in the report section, select the table visual from the visualizations.
  • In the table visual, drag and drop the Car name, Model, price from the field pane, and the created Measure value.
  • The screenshot below shows the filtered value based on the condition applied as either car names called Ford or Audi and displays the true or false value based on the condition applied.
Power BI DAX filter true false example
Power BI DAX filter true false example

This is how to use the filter function to check the true or false value based on the condition in Power Bi.

Check out: Power Query Add Column Date [15 Examples]

Power BI DAX filter if contains text

Let us see how we can filter the table data value using the contains string and Power Bi Dax filter function in Power bi.

In this example, we will use the vehicle table data, we will calculate the car price value by passing the text or string value of the car names to filter the value based on the text or string contains.

  • Open the Power Bi desktop and load the table data into it, From the ribbon click on the new measure option and apply the below formula:
SUM Value = 
VAR total =
    CALCULATE(
        SUM(Cars[Price]),
        FILTER(ALLSELECTED(Cars),
            IF(
                CONTAINSSTRING(LOWER(Cars[Car Names]),"Ford") ||
                CONTAINSSTRING(LOWER(Cars[Car Names]),"Audi"), "True", "False"
            )
        )
    )
RETURN
 total

Where,

  1. SUM Value = Measure name
  2. total = Variable name
  3. Cars = Table name
  4. Car Names, Price = Column name
  5. Contains string = function name
  • Now in the report section, select the table visual from the visualizations.
  • In the table visual, drag and drop the Car name, Model, price from the field pane, and the created Measure value.
  • The screenshot below shows that the card visually displays the filtered value based on the condition applied as either car names called Ford or Audi and displays the true or false value based on the condition applied.
Power BI DAX filter true false
Power BI DAX filter true false

This is how to filter the table data value using the contains string and Power Bi Dax filter function in Power bi.

Have a look: Power Query Add Column If Statement

If no filter is selected Power BI DAX

Let us see how we can display nothing selected in the filter, using the Power Bi Dax filter function in Power BI.

In this example, we will create two measures to check the no filter selected in the filter in Power BI.

  • Initially, open the Power BI desktop and load the data into the Power BI desktop, and from the ribbon click on the new measure option and apply the below formula:
Flag = 
ISFILTERED ( Cars[Car Model] )

Where,

  1. Flag = Measure Name
  2. ISFILTERED = function name
  3. Cars = Table name
  4. Car Model = column name
  • Now in the report section, select the slicer visual from the visualizations, and drag and drop the Car Model from the field pane.
  • Now create another measure and add the below-mentioned formula to check the no filtered value.
Check NoFilter = 
IF ( [Flag], SUM (Cars[Price] ), "NO Filter Selected" )

Where,

  1. Check NoFilter = Measure name
  2. Flag = Previously created measure value
  3. Cars = Table name
  4. Price = Column name
  • Now select the card visual from the visualization, drag and drop the created Measure value.
  • The screenshot below shows that the card visually displays the filtered value based on the value selected in the slicer visual.
If no filter is selected Power BI DAX
If no filter is selected Power BI DAX
  • The screenshot below shows that the card visually displays the no filtered value when none of the data is filtered from the slicer visual.
If no filter is selected Power BI DAX example
If no filter is selected Power BI DAX example

This is how to display nothing selected in the filter, using the Power Bi Dax filter function in Power BI.

Read: How to duplicate multiple columns using Power Query

Power BI DAX if filter selected

Let us see how we can display the selected filter value using the Power Bi Dax filter function in Power BI.

  • Initially, open the Power BI desktop and load the data into the Power BI desktop, and from the ribbon click on the new measure option and apply the below formula:
Selected Filter = IF(ISFILTERED ( Cars[Car Model] ),SUM (Cars[Price] ), "False")

Where,

  1. Selected Filter = Measure name
  2. Flag = Previously created measure value
  3. Cars = Table name
  4. Price = Column name
  • Now in the report section, select the slicer visual from the visualizations, and drag and drop the Car Model from the field pane.
  • Now select the card visual from the visualization, drag and drop the created Measure value.
  • The screenshot below shows that the card visually displays the filtered value based on the value selected in the slicer visual.
Power BI DAX if filter selected
Power BI DAX if filter selected

This is how to display the selected filter value using the Power Bi Dax filter function in Power Bi.

Read: How to add an empty column in Power BI

Power BI DAX if statement with filter

Let us see how we can use the filter function with the if statement condition in Power Bi.

In this example, we use the Vehicles table data to apply filters to obtain the result value as true or false based on the if filter condition.

  • Open the Power Bi desktop and load the table data into it, From the ribbon click on the new measure option and apply the below formula:
IF filter = 
VAR sumvalue =
    CALCULATE (
        SUM(Cars[Price]),
        FILTER (
            Cars,
            Cars[Car Model]="Q7" || Cars[Car Model]="Creta S"
        )
    )
RETURN
    IF ( sumvalue >= 800000, "False", "True" )

Where,

  1. IF filter = Measure name
  2. sum value = Variable name
  3. Cars = Table name
  4. Car Names, Price = Column name
  • Now in the report section, select the table visual from the visualizations.
  • In the table visual, drag and drop the Car name, Model, price from the field pane, and the created Measure value.
  • The screenshot below shows that the card visually displays the filtered value based on the condition applied as either a car model called Q7or Creta S and displays the true or false value based on the condition applied.
Power BI DAX if statement with filter
Power BI DAX if statement with filter

This is how to use the filter function with the if statement condition in Power Bi.

Additionally, you may like some more Power BI Tutorials:

This Power BI tutorial explains how to work with the Power BI Dax filter If functions based on the condition applied in the Power Bi Dax or measure with examples. Also, we discussed a few more topics mentioned below:

  • Power BI DAX filter multiple conditions
  • Power BI DAX filter true false
  • Power BI DAX filter if contains text
  • if no filter is selected Power BI DAX
  • Power BI DAX if statement with filter
  • Power BI DAX if filter selected
>