Power BI Slicer for Multi-Value Columns: Splitting Delimited Data for Better Filtering
In this article, we will create a slicer based on a data column containing multiple entries separated by a delimiter. The goal is for the slicer to display each entry as an individual item, allowing users to filter data without selecting each grouped entry manually.

As an example, the sample data is an asset inventory with each asset owned by one or more named individuals. In instances where an asset is owned by multiple individuals, their names are delimited by a semicolon. An individual may be an owner of one or more assets.
In our sample data, the individual named “Clark, Ethan” is listed as the singular owner of the assets named “QuickBolt” and “VersaBox” and the co-owner, with “Taylor, Benjamin”, of the asset named “SnapWorks”. If we add a slicer using the Contacts
field in our sample data, both entries for “Clark, Ethan” and “Clark, Ethan; Taylor, Benjamin” need to be selected to find all assets owned by “Clark, Ethan”. The goal of this exercise is to create a slicer allowing the user to select “Clark, Ethan” to display all of that owner’s assets regardless of co-ownership.

For this exercise, the source data is in a table named TBL_INVENTORY
, with two columns: Asset
and Contacts
.

Instructions
Preparing the Slicer Data
We need to create a new table with individual entries for the slicer. The query below splits grouped entries using a delimiter. For reference, the full query is provided with step-by-step explanations. Both the query and the resulting table are named TBL_CONTACTS
.
let
Source = TBL_INVENTORY,
#"Removed Other Columns" = Table.SelectColumns(Source,{"Contacts"}),
#"Duplicated Column" = Table.DuplicateColumn(#"Removed Other Columns", "Contacts", "Contacts - Copy"),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Duplicated Column", {{"Contacts - Copy", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Contacts - Copy"),
#"Trimmed Text" = Table.TransformColumns(#"Split Column by Delimiter",{{"Contacts - Copy", Text.Trim, type text}}),
#"Removed Duplicates" = Table.Distinct(#"Trimmed Text")
in
#"Removed Duplicates"
Source Data
We start by creating a blank query:
- From the
Home
ribbon in Power BI, clickGet data
and selectBlank query
. - The Power Query window is displayed.
- Set the initial data source by entering
= TBL_INVENTORY
in the command field.

Remove Other Columns
Next, keep only the Contacts
column:
- Highlight the
Contacts
column. - From the
Home
ribbon, clickRemove Columns
and selectRemove Other Columns
.

Duplicate Column
At this stage, only the Contacts
column remains.
- From the
Add Column
ribbon, clickDuplicate Column
. - We now have two column labeled
Contacts
andContacts - Copy
.

Split Column
- Highlight the
Contacts - Copy
column. - From the
Transform
ribbon, clickSplit Column
and selectBy Delimiter
. - The
Split Column by Delimiter
dialog box is displayed.

- In our sample data, the delimiter is a semicolon. In the
Select or enter delimiter
, selectSemicolon
. - For the
Split at
dropdown, selectEach occurrence of the delimiter
. - Expand the
Advanced options
. - Under
Split into
, selectRows
. - Click the
OK
button.

Trim Text
- Highlight the
Contacts - Copy
column. - From the
Add Column
ribbon, clickFormat
and selectTrim
.

Remove Duplicates
From the Home
ribbon, select Remove Rows
and click Remove Duplicates
.

Relating Tables
Next, we need to create a relationship between TBL_INVENTORY
and the newly created TBL_CONTACTS
table.

- In Power BI, switch to the
Model view
. - Create a relationship between
TBL_INVENTORY
andTBL_CONTACTS
by dragging theContacts
field inTBL_INVENTORY
to theContacts
field inTBL_CONTACTS
. - The
New relationship
dialog box is displayed. - Set the
Cardinality
toMany to many (*:*)
withCross-filter direction
set toBoth
. - Enable the
Make this relationship active
checkbox. - Click the
Save
button.

Add Visualizations and Slicers
Finally, let’s build the report by adding a table visualization and slicer:
- In Power BI, switch to
Report view
. - Add a
Table
visualization. - From
TBL_INVENTORY
, configure the table visualization by addingAsset
andContacts
toColumns
.

- Add a
Slicer
. - From
TBL_CONTACTS
, configure the slicer by addingContacts - Copy
toField
.

Results
In the screenshot below, the slicer on the right is based on individual contact names. Selecting “Clark, Ethan” filters the table correctly, displaying all entries associated with him, including those where he is a co-owner.

Summary
In this article, we created a slicer based on a delimited data column, allowing users to filter individual contact names easily. By preparing the slicer data and relating tables, we ensured that selecting a name in the slicer displayed all relevant assets, even those with co-ownership. This approach simplifies filtering and enhances the usability of asset inventory data in Power BI.