Showing results for 
Search instead for 
Did you mean: 
Helper III
Helper III

Create a table using Excel fields and input it in an email



I am trying to grab specific fields from an Excel, create a table, and then input it in a body of an email.


For more background, I have an excel sheet where if an email address is listed, a notification will be sent out to that user. However, the email address can be listed more than once. I need to send out just ONE email with all of the rows' information with that email address.



So for the example above, an email like below should get sent:





I was able to create this using the web version, but due to some limitations, I have to use the desktop version.


Any help would be appreciated.





Post Prodigy
Post Prodigy

Perhaps use Excel to remove the duplicates in the first instance ?



The duplicates aren't really the issue (I'm able to to that in the automation). Really, what I want is to pull the information from Excel and put it in the body of the email. However, 1 email per 1 email address listed in the Excel with ALL the information it has consolidated. 

Yes but if you have 2 identical email addresses are the row values the same ?

No, the row values are different. 


So it should send ONE email with a table of the different values. Please see the picture below.



Ahh thats where you lost me, initially you said all of the rows value, as in single row but you meant table, gotcha.

Sorry about that. I see how that's confusing. I just updated it as plural

So its the whole table ? no other conditions ?

Like I said excel / power query can remove the duplicate email addresses and put them into a wee table same sheet or other sheet, for each email send table ?

Super User
Super User

If you have the freedom to sort by email, do so.


Here is the logic after launching excel and sorting:

Get First Free Row

Set %PreviousEmail% to %''%

Loop 2 (assuming a title row) to %FirstFreeRow - 1% increment of 1

    'We will loop through each row with %LoopIndex% as the row number and grab the email from the current row and the next row in two separate variables into %CurrentEmail% and %NextEmail

If %LoopIndex% > 2

    Read from Excel at D and %LoopIndex - 1%


If %CurrentEmail% 'does not equal' %PreviousEmail%

    Capture the current row number as the %StartRow%


If %CurrentEmail% 'does not equal' %NextEmail%

    Send Email with Excel extracted from A and %StartRow% to D and %LoopIndex% NOTE:  LoopIndex is the EndRow

End (if)



Responsive Resident
Responsive Resident


This is an example PAD code, you can copy and paste in PAD.

This is using sql query processing and outlook desktop for sending email



- Office365 64 bit installed.

- Outlook desktop configured

- Download sample excel file from here 


PAD Code :


# ----------------CHANGE FILE PATH BELOW----------
SET FileExcel TO $'''C:\\Users\\abc\\Downloads\\Book1.xlsx'''
SET tableStart TO $'''<div><table border=\"1\" cellpadding=\"2\">'''
SET tablehead TO $'''<tr><th>Number</th><th>Name</th><th>Amount</th><th>Issues</th><th>Need to send email</th><th>Email Address</th></tr>'''
Outlook.Launch Instance=> OutlookInstance
SET ConnString TO $'''Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%FileExcel%;Extended Properties=\"Excel 12.0 Xml;HDR=yes\";'''
Database.ExecuteSqlStatement.ConnectAndExecute ConnectionString: ConnString Statement: $'''Select DISTINCT [Email Address]
from [Sheet1$]
''' Timeout: 30 Result=> QR_Email
    SET tableBody TO $'''%''%'''
    SET EmailAddress TO CI_Email['Email Address']
    Database.ExecuteSqlStatement.ConnectAndExecute ConnectionString: ConnString Statement: $'''Select *
from [Sheet1$]
where [Email Address] = \'%EmailAddress%\'
''' Timeout: 30 Result=> QR_Data
        SET tableBody TO $'''%tableBody%<tr><td>%CI_Data['Number']%</td><td>%CI_Data['Amount']%</td><td>%CI_Data['Name']%</td><td>%CI_Data['Issues']%</td><td>%CI_Data['Need to send email']%</td><td>%CI_Data['Email Address']%</td></tr>'''
    SET tableEnd TO $'''</table></div>'''
    Outlook.SendEmailThroughOutlook.SendEmail Instance: OutlookInstance Account: $'''''' SendTo: $'''''' Subject: $'''test''' Body: $'''%tableStart%
%tableEnd%''' IsBodyHtml: True




I'm not understanding where you're getting the "Set %PreviousEmail% to %''%" 


Is %PreviousEmail% the %EmailAddress%



My apologies.  I added another step (in BOLD) below.  You are working off of two major logics.


Logic 1)  If the Current Row Email is not the same as the Previous Row Email, get the Starting Row #

Logic 2)  If the Next Row Email is not the same as the Current Row Email, send the Email (from Start Row to Current Row)


Set %PreviousEmail% to %''% is simply there so that the variable is defined as (blank) before the IF logic that happens later.  This means your first row's email will not equal blank; therefore, it will declare the start row as 2 for the first email.  Without this line of code, the IF function would error out because %PreviousEmail% would not have been populated yet.


Best of luck!

Hi MichaelAnnis,


Thanks for your response! Are you also able to explain the first loop and how you're splitting between

 %CurrentEmail% and %NextEmail?



Current Email would be:


Read from Excel at D and %LoopIndex% to %CurrentEmail%


Next Email would be:


Read from Excel at D and %LoopIndex + 1% to %NextEmail%

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Top Solution Authors
Top Kudoed Authors
Users online (5,087)