Wildcard filter for comma separated list of values

You can easily create a wildcard filter that allows you to filter by a word or series of words on your chart using this post on Wildcard Filters. However, let's say you have a list of comma separated filter values that you'd like to filter on and it is too many to have to enter in one by one. With a find and replace tool (like this one) and a few lines of python we can filter by a given list of words easily. 

First create a filter that "Allows users to enter values."

Then use the find and replace tool to replace all commas with a dash - (this is because Periscope removes special characters from filter values but dashes do not get removed) 

Then include the filter in the select clause of your sql query with single quotes around it like below.

select
  lower(first_name) ||' '|| lower(last_name) as name
  , '[wildcard_filter]' as filter
from
  users

Then in the python editor, you can use these 3 lines to manipulate the string of filter values, filter the results, and then remove the filter column that we added in the sql. 

# SQL output is imported as a dataframe variable called 'df'
import pandas as pd

# replace the dashes with the regex pipe
all_filters = df['filter'][0].replace('-', '|')

# filter dataframe to only return results where the name matches the wildcard filter
df = df[df['name'].str.contains(all_filters)]

# drop the filter column to return desired output
df.drop('filter', axis=1, inplace = True)

periscope.table(df)

Here is an example of the results: 

 

 

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 2 wk agoLast active
  • 36Views
  • 1 Following