Functions in Power BI — (Table.FindText) | by Peter Hui | Towards Data Science

I’ve always been amazed at the simple find function. You can find anything that matches your criteria, even if your search item is hidden in different work sheets, open text or tables.
Just imagine, you can search for anything that appears anywhere in your raw data. Even if it is hidden somewhere in an open text field. Quite amazing!
How is this helpful? It’s very helpful if you are looking for a key word or a set of numbers that has importance, but you just don’t know where to look. This number can be in the open-text field, it could be in the name field etc.
Once found, you can combine these search results and tell a story with it. Sometimes, doing a find is just out of curiosity, but sometimes you may be surprised by what you’ve found.
I’ve used this Table.FindText function as a fraud detection exercise, It came in very handy because my tables were huge and I was just looking for one single individual. There are other ways this simple function can be helpful. You can use it as a historical search of account records and to answer some questions you may have.
Let’s get started!
Let’s take a look at the Table.FindText function on Microsoft.
In plain English, this is a function that uses a table as input and searches for an item within that table. It then returns a table with the rows that matches your criteria.
Let’s try this out.
The first step is tricky — maybe you are lucky to have a column of tables already set up for you, but I have to convert my binary files into table format from a folder.
It’s not that difficult and I use this function.
(FOLDER_PATH , FILENAME ) =>let    Source = Csv.Document(File.Contents(FOLDER_PATH&FILENAME)),    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])in   #"Promoted Headers"
If you connect Power BI using the folders option and have a list of binary files, you can convert these binary files into tables using the above function.
To add in a new function, simply go to Power Query > New Blank Query > Advanced Editor > Paste in the script
The FOLDER_PATH and FILENAME parameters in this query are the columns Power Query prepared for you once you connect to it.
Here is an example.
Now I will apply the function using the Invoke function selection. If you are confused about how to use functions, here is an article for you to help you get started. Functions are great!
After I apply the function, I get this output.
Great! Now I have a column of tables to apply my Table.FindText().
I’ll remove the columns I don’t need and only reflect the table column.
All we need to do now is apply our function by creating a new column. I want to see if the word “Apple” occurs anywhere in my tables.
Now when you drill down you can see “Apple” occurs in the table under the flavors column.
If I move it to another selection, you can see “Apple” occurs in the Stand column under “Appleton” as well.
Now to analyze your results, you can just combine all the files and the files will contain rows that only contain the word “Apple”.
Yes, my example is quite simple and I only have 10 tables, but think of it this way, if you are able to understand how to build a simple prototype, you can use this across any number of tables you have in your regular work :)
Table.FindText() is a neat function. Be imaginative with it, you can find your search selection in any column and any table.
Table.FindText() is a neat function. Be imaginative with it, you can find your search selection in any column and any table.
2. Remove some columns you don’t need in the beginning, it makes this run a lot faster!
3. The tricky part isn’t using the search function but converting the binaries into Tables.
There are other functions which you may find useful.
These functions will be useful if you already know the key words or numbers you are looking for and you know which columns to look. They are Table.Contains(), Table.ContainsAll() Table.ContainsAny().
I’ll be writing an article in the future about these as well.
Stay safe and thank you for reading!