Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Parsing CSV, Filtering JSON by a Dynamic Field, and Sending 1 Email with Filtered HTML Table to each of the dynamic field values

(0) ShareShare
ReportReport
Posted on by 25

Hello,

 

Running into a bit of a head scratcher. I had a report with line items for overdue courses which I was trying to manipulate in Power Automate to accomplish the result. Frustrated with my lack of progress, I have changed the incoming report to more closely resemble my desired output.

The report comes in like the following:

Manager E-mailPerson Full NameTotal Number of Courses
Manager E-Mail 1Person Name 140
Manager E-Mail 1Person Name 240
Manager E-Mail 1Person Name 338
Manager E-Mail 1Person Name 430
Manager Email 2Person Name 541
Manager Email 2Person Name 640
Manager Email 2Person Name 740
Manager Email 2Person Name 837
Manager Email 2Person Name 926
Manager Email 2Person Name 1020
Manager Email 2Person Name 111
Manager Email 2Person Name 121
Manager Email 2Person Name 131
Manager Email 3Person Name 1458
Manager Email 3Person Name 1542
Manager Email 3Person Name 1620
Manager Email 3Person Name 177
Manager Email 3Person Name 185

 

The goal for me here:

  • Parse CSV - done
  • Filter by Manger Email - this is dynamic and giving me trouble, seems to only work when I hard code the values and run in parallel, but I don't know the values ahead of time
  • Send 1 email to each of the Manager Email values with a summary of their employees with overdue courses - having trouble with this as well as it seems to loop for each of the line items even when trying to get the values from my filtered JSON

For the email filtering, I've tried creating an array variable and appending it:

LoufromNH_0-1661095869232.png

That didn't work, so now I've tried just filtering by the same field (doesn't seem to work either:

LoufromNH_1-1661095916300.png

For getting the email values, I've tried to use a union of the same variables, which seems to work, but it still runs for each of the above 19 line items:

LoufromNH_2-1661096044714.png

 

The complete JSON is functioning as desired prior to my desire to filter by Manger Email.

 

I'm pretty new at this but have had some success. Looking for any ideas as to how to make this work. Really just want to automate notifications on a periodicity to drive compliance.

 

Thank you,

Lou

  • LoufromNH Profile Picture
    25 on at
    Re: Parsing CSV, Filtering JSON by a Dynamic Field, and Sending 1 Email with Filtered HTML Table to each of the dynamic field values

    Thank you, Marco. All working now. 

    Slowly learning. I appreciate the help. 

  • MarconettiMarco Profile Picture
    3,812 Super User 2024 Season 1 on at
    Re: Parsing CSV, Filtering JSON by a Dynamic Field, and Sending 1 Email with Filtered HTML Table to each of the dynamic field values

    Hello @LoufromNH ,

    in regards of the "To" field in the Email action, you simply should add the "Current item" value, cause the email sending action is already contained in the Apply to each loop where the "from..." is the email manager.

     

    In regards of the blank table, you should use the expressions that I've mentioned in my previous post, eventually by replacing "Person Full Name" and "Total Number Of Courses" with your excel table column names.

    Please remind to add the "Create HTML table" outputs at the end of the HTML contained in the "Compose" action: 

    MarconettiMarco_0-1661146930752.png

    If are there any other issues, please share the detailed flow in Edit Mode.

     

    If I have answered your question, please mark my post as Solved.
    If you like my response, please give it a Thumbs Up.

    My blog site about Power Automate: https://powerautomatejoy.com/

    BR,

    Marco

  • LoufromNH Profile Picture
    25 on at
    Re: Parsing CSV, Filtering JSON by a Dynamic Field, and Sending 1 Email with Filtered HTML Table to each of the dynamic field values

    Well,

     

    A little messing around and I'm getting the appropriate number of emails, each with unique data that is populated.

     

    Now the only issue I'm having is making that "To" field in the email action dynamic based on the email for the action. When I select the "Manager E-Mail" field from the filterByManager step, it creates an apply to each loop which appears to send an email for each line item.

     

    The playing will continue until the problem is solved.

  • LoufromNH Profile Picture
    25 on at
    Re: Parsing CSV, Filtering JSON by a Dynamic Field, and Sending 1 Email with Filtered HTML Table to each of the dynamic field values

    Thank you, Marco.

     

    I'm now getting an appropriate number of emails going out, but the html table is blank. Additionally, the To in the email would need to be dynamic based on the table.

     

    I'm not using an excel sheet, so that might be the problem. The report comes in as csv and I convert it into JSON. Excel data is not an option in the system I'm generating the report from. Maybe I can convert it, but it still seems like the filtering should work with the JSON array.

     

    I'll keep playing with it.

  • Verified answer
    MarconettiMarco Profile Picture
    3,812 Super User 2024 Season 1 on at
    Re: Parsing CSV, Filtering JSON by a Dynamic Field, and Sending 1 Email with Filtered HTML Table to each of the dynamic field values

    Hello @LoufromNH ,

    please follow these steps:

    1. List the rows, in my case I'm using the Excel "List rows present in a table" action:

    MarconettiMarco_0-1661101239682.png

    2. Add a "Select" action where to grab only the Manager email:

    MarconettiMarco_1-1661101264859.png

     

    3. Add a "Compose" action in which put the following expression:

    union(body('Select'),body('Select'))

    MarconettiMarco_2-1661101297667.png

     

    4. Add an "Apply to each" control: put the previous Compose outputs in the "Select an output from previous steps" field

    MarconettiMarco_3-1661101333996.png

    5. In the Apply to each loop, add a "Filter array" action where filter the list based on the Manager email:

    MarconettiMarco_4-1661101384754.png

    6. Always in the Apply to each loop, add a "Create HTML table":

    - From: body grabbed from the "Filter array" action;

    - in the Values please use the following expressions:

    item()?['Person Full Name']

     

    item()?['Total Number of Courses']

    MarconettiMarco_5-1661101443943.png

    7. Always within the Apply to each loop, I suggest to add another Compose action and put the following html to format the table:

    <style>
    table {
     border: 1px solid #1C6EA4;
     background-color: #EEEEEE;
     width: 100%;
     text-align: left;
     border-collapse: collapse;
    }
    table td, table th {
     border: 1px solid #AAAAAA;
     padding: 3px 2px;
    }
    table tbody td {
     font-size: 13px;
    }
    table thead {
     background: #1C6EA4;
     border-bottom: 2px solid #444444;
    }
    table thead th {
     font-size: 15px;
     font-weight: bold;
     color: #FFFFFF;
     border-left: 2px solid #D0E4F5;
    }
    table thead th:first-child {
     border-left: none;
    }
    </style>

    At the end of the HTML, add the HTML table outputs:

    MarconettiMarco_6-1661101614487.png

    8. Always within the Apply to each loop, add the Outlook "Send an email (V2)" action and add the previous Compose outputs in the email body:

    MarconettiMarco_7-1661101666933.png

     

    Here the full flow:

    MarconettiMarco_8-1661101693140.png

    Here the output:

    MarconettiMarco_9-1661101709560.png

    So, each Manager will receive his own email with the employees list.

     

    If I have answered your question, please mark my post as Solved.
    If you like my response, please give it a Thumbs Up.

    My blog site about Power Automate: https://powerautomatejoy.com/

    BR,

    Marco

     

     

     

     

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 566 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 516 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 492