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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Counting number of ema...
Power Automate
Suggested Answer

Counting number of emails received in shared mailbox on daily basis

(1) ShareShare
ReportReport
Posted on by 563
I need to count number of emails received in shared mailbox on daily basis. Each email has a subject which includes AIS number. I am grouping emails by AIS number and then counting number of emails received.
 
The only problem is with count. Rest all looks fine. Everytime count shows as 1 which is wrong. Screenshot below of the power automate. Also in AISRefNo column i want to remove the prefix {"AISRefNo":} for each record. It should just show the AIS2736 without quotes. May i know how to achieve this?
 
Problematic Output
 
Expected Output
 
Power Automate
 
 
 
 
 
 
I have the same question (0)
  • Suggested answer
    11manish Profile Picture
    463 on at
    the issue is mainly with how grouping & counting is being done in Microsoft Power Automate.
     
    Why your count is always = 1
    Your current logic:
    • union(body('Select_2'), body('Select_2'))
    This is only used to remove duplicates, NOT to count occurrences.
    So:
    • You get unique AISRefNo 
    But count is always 1 ❌ (because you’re not actually counting)
     
    Correct Approach (Group + Count)
    You need 2 steps:
    Step 1: Extract clean AISRefNo (Fix your format issue)
    Instead of returning:
    • {"AISRefNo":"AIS2736"}
    Return plain text only
     
    Update your Select action:
    • AISRefNo → substring(item()?['Subject'], <start>, <length>)
    OR better (dynamic):
    • trim(replace(replace(item()?['Subject'],'AISRefNo:',''),'"',''))
    Output becomes:
    • AIS2736
    Step 2: Get unique AIS numbers
    Keep your union():
    • union(outputs('Select'), outputs('Select'))
    This gives:
    • [AIS2736, AIS0146, AIS2065]
    Step 3: COUNT occurrences (important fix)
    Now add:
     
    ➤ Apply to each (on unique AIS list)
    Inside loop:
    Filter array:
     
    • From: outputs('Select')
    • Condition: item()?['AISRefNo'] == items('Apply_to_each')
    Compose (Count):
    length(body('Filter_array'))
    Append to array:

    {
      "AISRefNo": items('Apply_to_each'),
      "Count": length(body('Filter_array'))
    }

    Final Output
    • AIS2736 → 3
    • AIS0146 → 2
    • AIS2065 → 5
    Clean Solution Summary
    Fix 1: Remove prefix
    • Use substring() or replace() → return only AIS value
    Fix 2: Count correctly
    Use:
    • union() → unique values
    • Filter array + length() → count
     
    Thanks
    Manish
     
     
  • Suggested answer
    Haque Profile Picture
    894 on at
     
    Please see my last post ( -on 21 Mar 2026 at 18:09:39) in your previous thread.
     
    There it was RBLxxxx and here it is AISxxxx, clearly the logic is same.
     
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 333

#2
David_MA Profile Picture

David_MA 245 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 202 Most Valuable Professional

Last 30 days Overall leaderboard