Count the number of data within Excel Column with Power Automate Desktop using database action COUNT() WITH GROUP BY

by

This article I will show how to count the number of cells that meet a criterion; for example, to count the number of gender appears in a gender column.

The Excel file have data with 10 rows, I want to count the number of gender in column E (Excel worksheet named “Sheet1”)

Download Excel File here

Click above link and press download button in Github at the top right
Count geder: Male, Female, and Genderqueer

Set Variable

Set parameter as follow:

Variable: Excel_File_Path

Value: Please input the Excel Path in your computer for example C:\Users\User\Desktop\TestCountCondition.xlsx

Set variable’s parameter

Open SQL connection

Read about Database action here

Open SQL’s parameter

You can use Connection string as per below code block:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%Excel_File_Path%;Extended Properties="Excel 12.0 Xml;HDR=YES";

Execute SQL statement

Below code block is a basic SQL for select all column in the table Sheet1

SELECT *
FROM [Sheet1$]

You can set the parameter in Power Automate Desktop as per below image (Select All Column in Table Sheet1)

SQL statement for SQL statement for Select All Column in Table Sheet1

Now, I will write SQL statement for count the number of gender appears in a gender column. In SQL language, we will use COUNT() WITH GROUP BY as per below code block:

SELECT
    gender,
    COUNT(id) AS id_count
FROM [Sheet1$]
GROUP BY gender

You can set the parameter in Power Automate Desktop as per below image (COUNT() WITH GROUP BY)

Close SQL Connection

Then, press save button and run the flow. After the flow run successfully click variable QueryResult2 in the variable tab

Result

Result in Power Automate Desktop
Compare data in Excel and Result in Power Automate Desktop

You can copy code from Github to Power Automate Desktop and download Excel file here

Paste Excel file at your desktop and run the flow

Did You Enjoy this Article?

Subscription to get new articles sent to your inbox each week for FREE

Question?

If you have any questions or feedback about this article please leave a message in the comments section below.

Subscribe to get new articles sent to your inbox each week for FREE