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 / Filtering array and se...
Power Automate
Answered

Filtering array and sending emails to specific people based on condition

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

 

I would really appreciate your help regarding this case.

I`m trying to make a flow that compare the results a KPI in two period in excel, if the values are 0 and 0 for last and current period send notification to the email in same row. for example TRS is sent only to Bayan.sefri@gmail.com .if the result of the two period is  0 and 1 or 1 and 1 no need to do anything.(please check the table)

 

 

KPILast period This period Email (The person responsible for the KPI) 
TRS00Bayan.sefri@gmail.com
ATS11whatever@gmail.com
TRI10Test@gmail.com

 

I did the following flow, but it is not working well

 

 

11

the expression written it pink is 

int(item()?['This peroid '])
is equal to
Int(item()?['Last perioud '])

22

my problems are two:

 

1- It sends an email to every one

2 -I don`t know if filter is the right solution and how to write its condition (if the value of previous period and this period is zero, filter the table and keep only the kpi`s with 0 and 0)

 

Your help is really appreciated!

 

 

Categories:
I have the same question (0)
  • Ellis Karim Profile Picture
    11,691 Super User 2025 Season 2 on at

    Please check that the value in the Apply to each loop is taken from the OUTPUT of the Filter array:

    ekarim2020_0-1629201214846.png

    and that you are selecting the email values from the Apply to each loop: items('Apply_to_each')['Email]

    Ellis

  • Community Power Platform Member Profile Picture
    on at

    Hello Ekarim,

     

    Thank you for replaying, I tried what you said but I`m nit sure if I implement it correctly, apply to each only had two options "Body" and "Item", and when I choose any of them, another apply to each is inserted to the flow.

     

    apply to each optionsapply to each options

     

     let me what do you think about this

  • eliotcole Profile Picture
    4,363 Moderator on at

    Your condition formula is just a bit wonky, mate, that's all, plus you're going to get matches for anything where both values are the same number ... whatever that number is.

     

    So, let's take a look at this, mate:


    @Anonymous wrote:

    int(item()?['This peroid '])

    is equal to
    Int(item()?['Last perioud '])

    So, first out, you need to get the spelling, spacing, and case right on all of that.

     

    I don't say that to insult, if your field names really do have those spaces after them (it seems that they at least are spelled that way) then that's all fine. But I would hazard a guess that someone will eventually correct those table column headings, so it might as well be you, and you can amend them here, too:

    int(item()?['This period'])

    is equal to
    int(item()?['Last period'])

    That second 'int' was capitalised.

     

    However, if you click the 'Edit in advanced mode' that will (should) look like this:

     

    @equals(int(item()?['This period']), int(item()?['Last period'])

     

    I believe, that in order to get only items where the number is zero and they match, then you need to filter like this:

     

    @equals(and(equals(int(item()?['This period']), 0), equals(int(item()?['Last period']), 0)), true)

     

    There you are essentially saying:

    Show a true value IF int(item()?['This period'] is equal to 0 AND int(item()?['Last period'] is equal to 0

    is equal to
    true

    The first side of the condition will only show a true value if both those numbers are 0, and the condition will only follow the yes branch if that happens.

     

     

  • Community Power Platform Member Profile Picture
    on at

    Thank so much Eliotcole,

    Regarding the spelling and spaces, English is not my mother tongue, so when I`m in hurry i don`t give spelling that much attention but you are totally correct, I `ll fix it.

      

    Thank you again for the code, i tried but an error occur I didn`t get what`s the problem 

    Filter array errorFilter array error

    let me know, if you have any idea about the error, your help is appreciated !!

     

     

  • eliotcole Profile Picture
    4,363 Moderator on at

    Oh, of course, I wasn't for a second suggesting that you were in any way deficient, there! As long as it works, who really cares how things are spelled. 🙂

     

    That said, you have spaces before and after the column headings, and that can be problematic if they aren't there in the original table. It was all just everything together, I thought it best to suggest ensuring that the sample data that's coming in is nailed down tightly, that's all.

     

    So, with that in mind, I think your referencing just needs a little tidying up, that's all, @Anonymous ... keep trying from scratch, and use the GUI to select the values that you need when building the expression. Just remember if you rename any column headings in the table, you might need to amend the expression here.

  • Jcook Profile Picture
    7,781 Most Valuable Professional on at

    Hi @Anonymous 

     

    Could you send over a copy of the excel file? You can dummy the data (put fake data) in the table before sending if needed.

     

  • Community Power Platform Member Profile Picture
    on at
  • Verified answer
    eliotcole Profile Picture
    4,363 Moderator on at

    Solution

    The excel table row connector passes the integers as strings, and it seems the easiest way to match them is to convert the zero to string, this worked for me:

     

    and(equals(item()?['This period'], string(0)), equals(item()?['Last period'], string(0)))

     

    solution - rows - filter.jpg

     

    So this is almost the same equation as I mentioned before, but we're removing the int() functions, and adding string() functions. Whatever works, right?

     

    If you clicked on the 'Edit in advanced mode' it will look like this, and you can paste this in (I think - if not, play with the column names😞

     

    @equals(and(equals(item()?['This period'], string(0)), equals(item()?['Last period'], string(0))), true)

     

     

    Whoop!

     

    Email Troubles

    For your troubles getting the data out of the filter.

     

    Test it without the email stage (just put a terminate action in to stop the flow) and once you can run it OK copy the body data from the filter, it should look a bit like this:

     

    [
     {
     "@odata.etag": "",
     "ItemInternalId": "a17af041-8bf0-428a-b2a2-58390f4d3b27",
     "Email": "Bayan.sefri@gmail.com",
     "KPI": "ML Production Volume",
     "This Period": "0",
     "Last Period": "0"
     },
     {
     "@odata.etag": "",
     "ItemInternalId": "64f2f9cf-3876-4256-924a-eb6863b04fa9",
     "Email": "Osamaasefri22@gmail.com",
     "KPI": "ML Dispatch Volume",
     "This Period": "0",
     "Last Period": "1"
     }
    ]

     

    Now create a Parse JSON action, click on the 'Generate from sample' button, and paste it in there, then click done.

     

    Once you've done that, you should have a Parse JSON action that looks like this:

    parse json.jpg

     

    Now if you run your Apply to each on the Body from the Parse JSON action then you can more easily pick the field that you wish to use in the email action. 🙂

    Apply to each.jpg

     

    ...

     

    Alternate Solution

    OK, here, to save some flow processing, I renamed the columns to have no spaces, so that I could do a single ODATA filter on the table (in case that it gets large😞

    ThisPeriod eq '0'

    rows - filter.jpg

    That string expression is so that when it looks at the LastPeriod column it compares it to a string version of the zero value ... as this is how it is passed through in the JSON.

     

    But if you want it without the ODATA and pure filtering:

    [to be updated in a second]

     

    The reason for taking the spaces out initially is that the excel ODATA filter cannot handle spaces. It also cannot handle 'and' or 'or', so only one query per excel ODATA apparently.

  • Community Power Platform Member Profile Picture
    on at

    You are GENIUSSSS !!

    It worked perfectly 😍

    Thank you @eliotcole  so much 

  • eliotcole Profile Picture
    4,363 Moderator on at

    My pleasure, mate!

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 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard