How to read a text and count its occurrence from a docx file in Power automate?

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.

read a text and count its occurrence from a docx file in Power automate

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.

How to read the text and its occurrence from the docx file in Power automate
How to read the text and its occurrence from the docx file in Power automate

Follow the below steps to create the flow using Power Automate.

See also  PowerApps nested gallery control example

Step 1: Log in to Power Automate, click on +Create -> select Automated Cloud Flow.

How to read the text and its occurrence from the docx file in Microsoft flow

Next, provide the flow name, and then select trigger action ‘When a file is created in a folder‘. Click on Create.

Using Power Automate read the text and its occurrence from the docx file
Using Power Automate read the text and its occurrence from the docx file

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.
How to read the text and its occurrence from the docx file in MS flow

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.
How to read the text and its occurrence from the docx file in flow

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'])
read the text and its occurrence from the docx file in Microsoft  flow

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.
read the text and its occurrence from the docx file in Microsoft flow

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')
read the text and its occurrence from the docx file in Microsoft Power Automate

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.
See also  How to set default value in Power BI Slicer

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.
read the text and its occurrence from the docx file in Power Automate

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.
read the text and its occurrence from the docx file in flow

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.

read a text and count its occurrence from a docx file in Power automate

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:

>