Jump to content

Search text in a Kusto/ADX table using any number of terms from Power BI


Recommended Posts

Guest DanyHoter
Posted

Search ADX text by multiple terms from PBI

 

 

 

Summary

 

 

 

 

In this article, I’ll describe how we can search an ADX/Kusto table using multiple words provided by the user.

 

Step by step

 

 

 

 

Connect to the table StormEvents in the database Samples on the ADX cluster help.

 

Make sure to use direct query.

 

 

 

448x382vv2.png.e7d70cae4e43035d73674751e1bd29a7.png

 

 

 

 

 

 

 

In the Power Query editor add a step to the M script

 

 

 

266x503vv2.png.b30bb9e3d3b2df0790942598c644a43d.png

 

 

 

 

 

The new step applies a filter to the column EventNarrative using the operator has_all.

 

This operator returns all rows that contain a list of terms in a text regardless of case.

 

If we wanted to find text that include at least one term from a list, we can use the operator has_any.

 

For the user to provide any number of words we take the string provided by the user and break it by the delimiter ~ using the split function.

 

The user can enter a search text like “one~two~three” to look for rows where the searched column includes “One” and “two” and “Three” as terms surrounded by special characters.

 

If the list of terms is known ahead of time, we could create a table of terms and allow selecting multiple from the table. In our case we assume any term can appear.

 

 

 

 

 

807x178vv2.png.390d0d7a7e010814f3f1716497793dea.png

 

 

 

 

 

= Value.NativeQuery( #"Removed Other Columns","| where EventNarrative has_all (split('snow~rain','~'))")

 

 

 

The M function Value.NativeQuery allow us to insert a KQL snippet anywhere in the generated query.

 

In our case the full query will be:

 

["StormEvents"]

 

| project ["StartTime"],["State"],["EventType"],["EventNarrative"]

 

| where EventNarrative has_all (split( "cold~snow",'~'))

 

 

 

Now we need to create a parameter that will replace the literal used for filtering.

 

 

 

437x487vv2.png.5685693f32b909bd8af556a196f5d92d.png

 

 

 

 

 

 

 

 

 

Once we create the parameter, we replace the literal with the parameter.

 

A better method will be to use a function that will get the list of words or one string with multiple delimited words.

 

 

 

1130x168vv2.png.349fe46d5152e9e79cbd3bfba3f12a2b.png

 

 

 

 

 

After we apply the query, we need to create an empty table so we can bind the parameter to a column.

 

There are no rows in the table because we ae not selecting from a known list.

 

In the model view, we can bind the column in this table to the parameter.

 

 

 

 

 

260x745vv2.png.365e33aee70dcead19a1b80986cc73ef.png

 

 

 

In the page we create a page level filter and use the is type of filter.

 

This allows us to input arbitrary values.

 

mediumvv2px400.png.75f4d49ff4bd3cb191cf02271e2bd7e0.png

 

 

 

 

 

We add to the page a table with the columns from the storms query and a measure that shows the numbers of rows that are returned by the filter.

 

 

 

mediumvv2px400.png.bee82918caae1e39bc5eecbe45c69917.png

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...