In this Power Automate tutorial, we will see how to read a text and count its occurrence from a docx file in Power Automate.
So here I have a Word file with the below content in the SharePoint folder. We will read the text and count the occurrence of the word ‘example‘ using Power Automate. We will convert the Word file into a Text file to read the text.
To create this flow we will use 3rd party action i.e. Convert file from encodian, to convert the file from text. To use the actions coming under Encodian, you need the API Key.
To get the API Key, go to this link, and fill out the form to activate the free trial. Also, it will generate an API key for you.
Let’s create the Flow that will read the word file and count the occurrence of words in the content using Power Automate.
Read a text and count its occurrence from a docx file in Power automate
Here we will see how to read text and sites occurrence from the docx file in Power Automate.
Before we start creating the flow you must set up the Sharepoint folder, where you will upload the Word file.
Then you must have the encodian API Key, so you can configure the action with the connector. After that, you can use the action in your flow.
Follow the below steps to create the flow using Power Automate.
Step 1: Log in to Power Automate, click on +Create -> select Automated Cloud Flow.
Next, provide the flow name, and then select trigger action ‘When a file is created in a folder‘. Click on Create.
Now, you can see trigger action is added to the flow. Provide the below information:
- Site address: Select or Provide the SharePoint site address.
- Folder Id: provide the folder Id.
Step 2: Click on the +New step -> select Convert word-Encodian action. Then provide the below information:
- Output Format: Select the format as TXT.
- File name: Select or Provide the file name.
- File content: Provide the File content from dynamic content.
- Page Orientation: Select the Page Orientation as Inherit.
- Page Size: Select the page size as Inherit.
Step 3: To convert the output of the above action to string, so click on the +New step -> select Compose action. Then provide the below information:
- Inputs: Provide the below expression:
base64ToString(outputs('Convert_Word')?['body/FileContent'])
Step 4: Click on the +New step, select Initialize variable action, then provide the below information:
- Name: Provide the name as Count
- Type: select the type as Integer.
- Value: provide the value as -1.
Step 5: Next click on the +New step, and select the Compose action. Then provide the below information:
- Inputs: provide the below expression
split(outputs('Compose'), 'example')
Step 6: Now we will iterate through the output of the above compose action. Increment the count by 1 in every occurrence of the word in the text.
So, click on the +New step -> select ‘Apply to each action’. Then provide the below information:
- Select an output from the previous steps: Select the output of the compose action from dynamic content.
Then click on Add an action and select the Increment variable action. Then provide the below information:
- Name: Select the name as Count from the dropdown.
- value: Provide the value as 1.
Step 7: To show the output, click on the +New step -> select Compose action. Then provide the below information.
- Inputs: Select the variable from the dynamic content.
Step 8: To run the flow click on Test icon, click on the Test icon-> select Manually -> click on Test -> configure the action with connectors, then click on Run flow -> Then click on Done.
Now you can add the file to the folder and you can see your flow ran successfully. And you will expand the last compose action you can see the occurrence of text. The below output shows, the word ‘example’ contains 3 times on the word document.
Conclusion
In this Power Automate tutorial, we saw how to read a text in a Word file and counts its occurrence from the docx file in Power Automate.
You may also like:
- Format date to iso 8601 in Power Automate
- Add Hyperlinks to SharePoint List Items Using Power Automate
- How to Add Item to SharePoint list using Power Automate
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.