web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to Separate and S...
Power Automate
Unanswered

How to Separate and Sort Email Attachments by Type in Excel Using Power Automate?

(1) ShareShare
ReportReport
Posted on by 8

Hi everyone,

I’m working on a flow in Power Automate where I want to process incoming emails with attachments and organize the details in an Excel file. Here’s what I’m trying to achieve:

  1. Trigger: When an email arrives.
  2. Check for Attachments: Determine if the email contains any attachments.
  3. Sort Attachments: Separate attachments by their type (e.g., images like PNG, JPG; documents like PDF, Word).
  4. Log Details in Excel: Add a new row in an Excel sheet with details like email subject, sender, and a categorized list of attachments.
 This is my current flows:
 

I have a flow that uses multiple "Apply to Each" loops to handle email attachments. Is there a more efficient way to process and categorize these attachments, and can this be done without creating files in SharePoint?

Categories:
I have the same question (0)
  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at
    My proposal with one Apply to each that loops over the Attachment types (just to have less actions in the flow):
     
    Apply to each (Attachment type) is an array of arrays of the types you are looking for (you probably want to add some more types)
    [
    	[
    		"image/png"
    	],
    	[
    		"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    		"application/pdf"
    	]
    ]
     
    FilteredAttachments checks if there are Atachments with these types
    From
    @triggerOutputs()?['body/attachments']
    Filter
    @items('Apply_to_each')
    contains
    @item()?['contentType']
     
    FilteredAttachmentNames gets the names of these attachments
    From
    @body('FilteredAttachments')
    Map
    @item()['name']
    Compose the resulting object that you might add as a row to your Excel file
     
    {
    "Subject": @{triggerOutputs()?['body/subject']},
    "Sender": @{triggerOutputs()?['body/from']},
    "Image Files": @{join(body('FilteredAttachmentNames')[0], ', ')},
    "Document Files": @{join(body('FilteredAttachmentNames')[1], ', ')}
    }
     
    The Compose's output looks like this:
    {
      "Subject": "Just a test",
      "Sender": "Chriddle@example.com",
      "Image Files": "io.png",
      "Document Files": "Manifesto of the Communist Party.pdf, A Contribution to the Critique of Political Economy.pdf, test.docx"
    }
     
     
  • Efa1609 Profile Picture
    8 on at
    Hi @Chriddle its work but the output only a text. I need to be able to click on the output and open the images or documents.
  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at
    You can push this to the limit by using xpath()
    join(
    	xpath(
    		xml(json(concat('{"Root":{"Item":',triggerOutputs()?['body/attachments'],'}}'))),
    		concat(
    			'//Item[',
    				'contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document"',
    				'or contentType="application/pdf"',
    			']/name/text()'
    		)
    	),
    	', '
    )
     
    Output:
    {
      "Document Files": "Manifesto of the Communist Party.pdf, A Contribution to the Critique of Political Economy.pdf, test.docx"
    }
     
     
  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at
    I need to be able to click on the output and open the images or documents.
    You should have told me ;)
  • EI-06081227-0 Profile Picture
    8 on at
    @Chriddle Is there any other way to be able to click the link in the excel?  I tried to use the xpatch() as you recommended but its only print out the same output text and not will able to be open the attachment or images.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard