Forum Discussion
Slicer to Filter Substring
- 4 years ago
I assume that you have a very good hang of DAX. I hope you will be able to adapt this my measure to yours.
Basically, you should start by creating a disconnected table that looks like the one below:
Then write a measure that looks like the below:
Row Count =VAR SelectedUniqueProduct =SELECTEDVALUE ( 'Product'[Unique Product] )VAR ContainSelection =FILTER (ALL ( 'Table'[Product] ),CONTAINSSTRING ( 'Table'[Product], SelectedUniqueProduct ))RETURNCALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Product] IN ContainSelection )My result looks like the below:If this works for you, kindly mark as solution to allow other community members who may have similar challenges find solutions quickly. - 4 years ago
If I understand the ask correctly, when you select Beef, Cheese, Meat, the measure should respectively give you 5,3,5.
You can use a measure like this
Measure = VAR _1 = ADDCOLUMNS ( 'Table', "newString", SUBSTITUTE ( 'Table'[Product], ",", "|" ) ) VAR _2 = GENERATE ( _1, ADDCOLUMNS ( GENERATESERIES ( 1, PATHLENGTH ( [newString] ) ), "splitString", TRIM ( PATHITEM ( [newString], [Value], TEXT ) ) ) ) RETURN COUNTX ( FILTER ( _2, [splitString] = SELECTEDVALUE ( 'ProductSlicer'[Product] ) ), [splitString] )
Another option would be to split out the comma separated list into separate rows using power query.
1) add an index so you can use countdistinct if you need to know original number of rows.
2) Select the comma separated column and in the transform tab click Split Column by Delimiter. Select a comma deliminator. Click the arrow to expand the advanced options and then select rows.
That should make your dax simpler and allow for easy filtering.