In this Power Bi tutorial, we will learn what Power BI IF contains and how to work with the Power BI Measure if the text contains different examples in Power Bi. We will also cover the below headings:
- Power BI Measure If Text equals then
- Power BI Measure If Text then Dax
- Power Query checks if a text contains
- Power BI checks If the Text blank
- Power BI checks If the Text is a number
- Power BI checks If Text exists in another table
Power BI IF contains
The power BI CONTAINS() function returns if values for all referred columns exist then it returns a true value else it returns a false value.
Below is the syntax for the Power Contains Function:
CONTAINS(<table>, <columnName>, <value>[, <columnName>, <value>]…)
In the following, we will see how to use the Contains function in Power BI.
Power BI Measure If Text Contains
Let us see how to find that contains a specified value using the Power Bi Contains function in Power BI.
In this example, we will use the below Stocks table data as a data source and find the text values using the Power Bi Dax functions in Power BI.
Log in to the Power Bi desktop and load data using the get data option. Once the data has been loaded, select the new measure option and use the below formula:
Text Contains = CONTAINS(Stocks, Stocks[Symbol],"AAPL")
Where,
- Text Contains = New Measure name
- CONTAINS = Function Name
- Stocks = Table Name
- Symbol = Column Name
Select the table visual from the visualization, drop the Stock name, Symbol, and the created measure value into the columns section as shown below:
In the below screenshot, you can see if the text value contains the mentioned value it returns the true value else false.
This is how to find that contains a specified value using the Power Bi Contains function in Power BI.
Power BI Measure If Text equals then
Here we will see how to create a measure to find the text value using the Power BI If function in Power BI.
In this example, we will use the measure if the text value equals then match else it displays the value mismatch.
Load data using the get data option into the Power Bi desktop. Click on the new measure option and apply the below-mentioned formula:
Text equals = If( SELECTEDVALUE(Stocks[Symbol])="ORCL","match","mismatch")
Where,
- Text equals = New Measure name
- SELECTEDVALUE= Function Name
- Stocks = Table Name
- Symbol = Column Name
From the visualization select the table visual, then drag and drop the Stock name, Symbol, and the created measure Text equals value into the columns section as highlighted below:
The Screenshot below displays the text value if the text equals the mentioned text then matches else it displays the value mismatch.
This is how to create a measure to find the text value using the Power BI if function in Power BI.
Power BI Measure If Text then Dax
Let us see how to create a calculated column of text value using the Power Bi Dax function in Power BI.
In this example, we will add a new calculated column to find if the text value matches with mentioned value else it displays a blank value in Power Bi.
Open and Load data using the get data option into the Power Bi desktop. Click on the new column option under the modeling tab and apply the below-mentioned formula:
Measure If Text = IF(
ISERROR(
SEARCH("A",Stocks[Symbol])
),
BLANK(),
"True"
)
- Measure If Text= New Calculated column
- SEARCH= Function Name
- Stocks = Table Name
- Symbol = Existing Column Name
In the below screenshot, you can see that the newly added column displays the result as true when the Symbol column starts with the text value A. Else, it displays the blank value.
This is how to create a calculated column of text value using the Power Bi Dax function in Power BI.
Power Query checks if a text contains
Here we will see how we can check if a text contains a specified value using the Power Query editor in Power BI.
In this example, we will use the Query editor to add a custom column, if the specified text value matches with the text contains column then it returns the true value else false.
To achieve this follow the below-mentioned steps:
Step:1
Load the data into the Power Bi desktop, and under the Home, tab selects the transform data option as shown below: It will automatically redirect to the Power Query editor.
Step:2
In the Power Query editor, Add a custom column by selecting Add Column-> Custom column as highlighted below:
Step:3
- In the custom column pop-up window, enter the new column name and add the below-mentioned formula and click on the ok button.
if(Text.Contains([Symbol],"MSFT")) then "TRUE" else "FALSE"
Step:4
- In the below screenshot, we can see that the newly added custom column displays the value based on the condition applied.
- If the Symbol column contains the text MSFT then it returns the true value else False.
- Click on Close & Apply under the home tab, so that the changes will be reflected on the Power Bi desktop.
= Table.AddColumn(#"Changed Type", "Text Contains", each if(Text.Contains([Symbol],"MSFT")) then "TRUE" else "FALSE")
This is how to check if a text contains a specified value using the Power Query editor in Power BI.
Power BI checks If the Text Blank
Let us see how to show the text value if the row is empty or blank using the Power Bi Blank function in Power Bi.
In this example, we will see if the rows are empty and then displays the text value as missing data else it displays the values presented in the rows.
Load data using the get data option into the Power Bi desktop. Once the data has been loaded, select the new measure option and use the below-mentioned formula:
Text Blank = if( SELECTEDVALUE(Stocks[Symbol])= BLANK(),"Missing Data",SELECTEDVALUE(Stocks[Symbol]))
Where,
- Text Blank = New Measure name
- SELECTEDVALUE= Function Name
- Stocks = Table Name
- Symbol = Column Name
Select the table visual from the visualization, drag and drop the Stock name, Symbol, and the created Text Blank measure value into the columns section as shown below:
The Screenshot below displays the value as missing data whenever the symbol column has empty or blank row values else it displays the existing row values in it.
This is how to show the text value if the row is empty or blank using the Power Bi Blank function in Power Bi.
Power BI checks If the Text is a number
Here we will see how to check if the text is a number using the Power Query editor in Power BI.
In this example, we will see the text column is a text data type then it displays the true value if the text column contains the null value which is of number data type then it returns a false value.
- Load the data into the Power Bi desktop, and Select the Home tab -> to transform data option, It will automatically redirect to the Power Query editor.
- In the below screenshot, you can see that the symbol column is of the text data type (highlighted in red).
- To check the value of the text data type add a custom column and use the below-mentioned formula by selecting select the Add Column-> Custom column in the power query editor.
=if(Value.Is(Value.FromText([Symbol]), type text)) then "TRUE" else "FALSE"
- In the below screenshot, we can see that the newly added custom column displays the value based on the condition applied.
- If the Symbol column contains the text data type value then it returns the true value else it returns the False value.
- Click on Close & Apply under the home tab, so that the changes will be reflected on the Power Bi desktop.
= Table.AddColumn(#"Removed Columns", "Text Datatype", each if(Value.Is(Value.FromText([Symbol]), type text)) then "TRUE" else "FALSE")
This is how to check if the text is a number using the Power Query editor in Power BI.
Power BI checks If Text exists in another table
Let us see how we can check if text exists in another table in Power BI.
In this example, we will use two tables to check if the text exists in another table returns the true value or else the false value.
Table:1
Table:2
Load the table data into the Power Bi desktop, and make many to one relationship in the model view as shown below:
Click on the new column option under the modeling tab and apply the below-mentioned formula:
Flag = IF (Stocks[Purchase Price] IN DISTINCT ( 'Table 2'[Purchase Price]), "TRUE"," FALSE" )
Where,
- Flag = New Calculated column
- DISTINCT= Function Name
- Stocks = Table Name
- Purchase Price = Existing Column Name
- Table 2 = Another table name
In the below screenshot, you can see that the newly added column displays the result as true when the Symbol column matches the purchase price value. Else, it displays the false value.
This is how to check if text exists in another table in Power BI.
In this Power Bi tutorial, we have learned what Power BI IF contains and how to work with the Power BI Measure if the text contains different examples in Power Bi. We also covered the below headings:
- Power BI Measure If Text equals then
- Power BI Measure If Text then Dax
- Power Query checks if a text contains
- Power BI checks If the Text blank
- Power BI checks If the Text is a number
- Power BI checks If Text exists in another table
You may like the following power bi tutorials:
- Power BI Conditional Formatting Based on Text
- Power BI Switch Multiple Conditions
- Power BI Month over Month Change
- Calculate Percentage of Rows in Power BI
- Calculate Percentage of Two Columns in Power BI
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com