Keyword Filter =
VAR SearchTerm = LOWER( TRIM( 'Keyword Search Parameter'[Keyword Search Parameter] ) ) // Get input, lowercase, remove whitespace
VAR CurrentKeywords = LOWER( SELECTEDVALUE( 'YourDataTable'[YourKeywordColumn] ) ) // Get keywords for the current row, lowercase
RETURN
IF (
ISBLANK( SearchTerm ), // If search box is empty...
1, // ...show everything
IF (
CONTAINSSTRING( CurrentKeywords, SearchTerm ), // Check if keywords contain the search term
1, // Show row if match found
0 // Hide row if no match
)
)
Especially "Keyword Search Parameter". I have all my keywords stored in a column called "Keywords" and they are entered like: "Keyword1,Keyword2...Keywordn"
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Okay, let's break down that DAX measure step by step, focusing on the Keyword Search Parameter and how it interacts with your Keywords column.
You are absolutely right, Keyword Search Parameter is not a column from your original data.
What is 'Keyword Search Parameter'[Keyword Search Parameter]?
Creating the Search Box: In Power BI, when you go to Modeling > New Parameter > Text, you're creating something specific. Let's say you named the parameter Keyword Search Parameter.
Power BI's Action: Power BI automatically does two things:
It creates a new, simple, disconnected table in your data model. This table is also typically named Keyword Search Parameter.
Within that table, it creates a single column, often also named Keyword Search Parameter. This column has just one row.
The Link to the Slicer: The Text Parameter feature also automatically adds a slicer to your report page (unless you uncheck that option). This slicer is specifically linked to that single column in the Keyword Search Parameter table.
Capturing User Input: When a user types something into that slicer on your report, the text they type is stored as the single value in the 'Keyword Search Parameter'[Keyword Search Parameter] column within that special generated table.
So, 'Keyword Search Parameter'[Keyword Search Parameter] is simply the way DAX references the column that holds the text currently entered by the user in the search box (slicer).
VAR SearchTerm = ...: This declares a variable named SearchTerm. Variables make your DAX code cleaner and sometimes more efficient.
'Keyword Search Parameter'[Keyword Search Parameter]: This is where the measure gets the text that the user has typed into the search slicer (the one you created using Modeling > New Parameter > Text).
TRIM(...): This function removes any spaces from the beginning or end of the text the user typed. This is good for cleaning up accidental whitespace.
LOWER(...): This function converts the search term to all lowercase letters. This makes the search case-insensitive. So, if the user types "Gloves", it will be converted to "gloves" before searching.
Result of this line: The SearchTerm variable now holds the cleaned, lowercase version of whatever the user typed into the search box. If the search box is empty, SearchTerm will be BLANK().
dax
VAR CurrentKeywords = LOWER( SELECTEDVALUE( 'YourDataTable'[YourKeywordColumn] ) )
VAR CurrentKeywords = ...: Declares a variable named CurrentKeywords.
'YourDataTable'[YourKeywordColumn]: This is the placeholder for your actual column name containing the comma-separated keywords. Based on your question, you would replace this with 'YourTable'[Keywords] (assuming your table is named YourTable and the column is named Keywords).
SELECTEDVALUE(...): This is a DAX function often used in row context. When this measure is used as a filter on a visual (like a table), Power BI effectively evaluates the measure for each row of the table data. In that specific row's context, SELECTEDVALUE('YourTable'[Keywords]) returns the value from the Keywords column for that particular row.
LOWER(...): This converts the keyword string from your data column (e.g., "gloves,fingers,hand") into all lowercase letters (e.g., "gloves,fingers,hand"). This is crucial because the CONTAINSSTRING function (coming next) will compare lowercase to lowercase, ensuring a case-insensitive search against your data as well.
Result of this line: The CurrentKeywords variable now holds the lowercase, comma-separated keyword string for the specific row being evaluated by the filter measure.
dax
RETURN
IF (
ISBLANK( SearchTerm ),
1,
IF (
CONTAINSSTRING( CurrentKeywords, SearchTerm ),
1,
0
)
)
RETURN ...: This specifies the final value that the Keyword Filter measure will output for each row it's evaluating.
IF ( ISBLANK( SearchTerm ), 1, ... ): This is the first part of the logic.
ISBLANK( SearchTerm ): Checks if the SearchTerm variable (which holds the user's input) is blank. This is true when the user hasn't typed anything in the search box.
If TRUE (search box is empty): The measure returns 1. Returning 1 for a filter measure means "show this row". So, if nothing is typed, all rows are shown.
If FALSE (something is typed): The second part of the IF statement is executed, which is another IF statement.
IF ( CONTAINSSTRING( CurrentKeywords, SearchTerm ), 1, 0 ): This is the second part of the logic, only run when the user has typed something.
CONTAINSSTRING( CurrentKeywords, SearchTerm ): This is the core search function. It checks if the text string in the CurrentKeywords variable (the lowercase string from your data's Keywords column for the current row) contains the text string in the SearchTerm variable (the lowercase text the user typed).
Example: If CurrentKeywords is "gloves,fingers,hand" and SearchTerm is "finger", CONTAINSSTRING will return TRUE.
Example: If CurrentKeywords is "shirt,cotton,summer" and SearchTerm is "glove", CONTAINSSTRING will return FALSE.
If TRUE (the CurrentKeywords contain the SearchTerm): The measure returns 1. This means "show this row".
If FALSE (the CurrentKeywords do not contain the SearchTerm): The measure returns 0. This means "hide this row".
In Summary:
The measure works by:
Getting the user's input from the search box and making it lowercase.
For each row in your data table, getting its keyword string and making it lowercase.
If the search box is empty, it says "show the row" (returns 1).
If the search box is not empty, it checks if the lowercase keywords for that row contain the lowercase text from the search box. If yes, it says "show the row" (returns 1); otherwise, it says "hide the row" (returns 0).
When you add this measure to a visual's filter pane and set it to "is equal to 1", the visual will only display the rows where the measure calculated a 1.
Action for you: Make sure to replace 'YourDataTable'[YourKeywordColumn] in the measure with the actual name of your table and your keyword column, like 'YourTable'[Keywords].
User
Hm, it still doesn't work quite because if I do Search Box[Keyword], then Keyword will be marked as red, though I do get the search box and all
Assistant
Ah, you are absolutely right! My apologies, the placeholder name 'Keyword Search Parameter'[Keyword Search Parameter] was probably confusing because it's the default behavior of the Text Parameter feature, not necessarily what you named it.
The red underline on [Keyword] in Search Box[Keyword] indicates that Power BI doesn't recognize a column specifically named Keywordwithin the table that was automatically created by the "Search Box" parameter.
Let's clarify exactly what happens and how to reference it correctly in DAX.
What happens when you create a Text Parameter named "Search Box":
When you go to Modeling > New Parameter > Text and type "Search Box" into the "Name" field:
Power BI automatically creates a new, disconnected table in your data model. The name of this table is "Search Box".
Inside that table, it creates a single column. The name of this column is also "Search Box".
It also adds a slicer to your report page, linked to this 'Search Box'[Search Box] column.
So, the column that holds the text the user types into the search box is not called [Keyword]. It's called [Search Box]. And it's within the table called 'Search Box'.
Correcting the DAX Measure:
You need to reference the column from the parameter table using its correct name.
dax
Keyword Filter =
VAR SearchTerm = LOWER( TRIM( 'Search Box'[Search Box] ) ) // <--- CORRECTED REFERENCE
VAR CurrentKeywords = LOWER( SELECTEDVALUE( 'YourDataTable'[Keywords] ) ) // <--- Reference to YOUR data table and column
RETURN
IF (
ISBLANK( SearchTerm ),
1, // Show all if search box is empty
IF (
CONTAINSSTRING( CurrentKeywords, SearchTerm ), // Check if keywords contain the search term
1, // Show row if match found
0 // Hide row if no match
)
)
Explanation of the Corrections:
'Search Box'[Search Box]: This is the corrected way to reference the column where the user's search input is stored.
'Search Box' is the name of the table created by the Text Parameter (enclosed in single quotes because it has a space).
[Search Box] is the name of the column within that table (enclosed in brackets).
'YourDataTable'[Keywords]: This part needs to correctly reference your actual data table and the column within it that contains the comma-separated keywords.
Replace 'YourDataTable' with the actual name of the table that contains your product data.
Replace [Keywords] with the actual name of the column in that table where you put the keywords (you mentioned it's called "Keywords", so this part is likely correct unless your table name is different).
Steps to Fix:
Open the DAX measure you created.
Find the line VAR SearchTerm = ...
Replace the placeholder reference ('Keyword Search Parameter'[Keyword Search Parameter]) with ('Search Box'[Search Box]).
Find the line VAR CurrentKeywords = ...
Replace the placeholder reference ('YourDataTable'[YourKeywordColumn]) with the actual name of your main table and your Keywords column, like ('YourActualTableName'[Keywords]).
Save the measure.
Ensure this measure is applied as a filter on your visual, set to is equal to 1.
The slicer generated by the "Search Box" parameter should now correctly control the filter.
Let me know if you encounter any further issues! It's all about getting those table and column names referenced exactly right in DAX.