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 / For Each / Loop / If o...
Power Automate
Unanswered

For Each / Loop / If on 2 Excel columns

(0) ShareShare
ReportReport
Posted on by

Hi All,

 

Excel, in Sheet1 I have 2 columns with 5 rows, keeping it simple.

Column 1 has unique account numbers, 1001,1002,1003,1004,1005.

Column 2 has the account status, its either DR or CR.

If "DR" then skip, If "CR" then print the account number (1001 etc).

 

I have retrieved both columns into separate lists, im getting output, no errors, just not the desired result.

More often than not im getting all the values from column 1 ( account numbers ) written rather than the individual account number.

There's a bit more to the flow but the above explains the guts of it...

 

Thanks

I have the same question (0)
  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    Once you have both columns in separate lists (%Accounts% and %Status%), and assuming there is no title row in either, so [0] is value 1 and value 1 of %Accounts% directly corresponds with value 1 of %Status%:

     

    Create list %CreditAccounts%

    Loop 0 to %Accounts.Count - 1% increment of 1

        If %Status[LoopIndex]% = CR

            Add %Accounts[LoopIndex]% to list %CreditAccounts%

       End (If)

    End (Loop)

     

    At the end, %CreditAccounts% is a list of only your credit accounts.

     

     

  • UK_Mike Profile Picture
    on at

    Hi Mike,

     

    Parameter 'End to': Operator '-' can't be applied to 'Text value'.

     

     

    Thanks

     

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Is that in the LoopIndex Limit?

  • UK_Mike Profile Picture
    on at

    Yes Mike

  • UK_Mike Profile Picture
    on at

    Screenshot 2022-02-01 173046.pngScreenshot 2022-02-01 173106.png

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    %ColumnAsList_ID.Count - 1%   .Count is a property of a list which counts the number of rows in the list.  Because it is a 0 based index, we take 1 off.  So, if there are 20 rows, we got [0] to [19] to represent rows 1-20.

     

    Good luck.

  • UK_Mike Profile Picture
    on at

    FUC###################################

     

    Really sorry Mike, school boy error on my part.

    Jesus ive incorporated that .count a million times in other flows... 

    Error resolved

    Will get back to ya 😂😂😂😂

     

    Many thanks Mike

  • UK_Mike Profile Picture
    on at

    Worked perfectly, just have to apply this rationale to the actual flow.

    See you in part 2.... 🤣

     

    Many thanks as always... 😘

  • UK_Mike Profile Picture
    on at

    Hi Mike,

     

    I think I jumped the gun on my end, your solution worked perfectly but there was only one value to write, as in

    IF =CR "Then do this "    writes the value correctly.

    However when there are 2 or more correct values that = CR it writes incorrectly.

    Ive added a shot of the input and output columns.

    All the variable lists produced are correct, especially the %List% which contains 1002,1005,1008.

    Hope it makes sense...

     

    Screenshot 2022-02-02 174800.pngScreenshot 2022-02-02 174829.png

     

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Because you are writing the list on every loop.

     

    First loop, 1002

    Second loop, 1002 and 1005

    Third loop, 1002 1005 and 1008

     

    If you want to do it this way, you can:

    Option 1, take everything but "Add item to list" out of the If...then write the list 1 time at the end to D2

     

    OR

     

    Option 2, inside the If, on "Write to Excel"  replace "List" with "ColumnAsList_ID.[LoopIndex]%

     

    Good luck.  The point of the List was so that you have them all in a list inside of PAD, but if you need that list copied somewhere, you can copy it as you go (Option 2), or write the list after the whole thing is done (Option 1).

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

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard