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 / Loop the number of uni...
Power Automate
Unanswered

Loop the number of uniqe records inside a For-Loop

(0) ShareShare
ReportReport
Posted on by 20

Lets say I have a for-each loop in PAD, and we have to do some web automation for the departments.

I know from a div link inside the web if we are in the 'IT' or 'HR' page at the moment. Instead of checking that div every single loop, is there a way to say

 

FOR EACH department:

   Loop 'x' times (x is based on the number of rows for 'IT' first then 'HR')

        Do actions

    End

End

 

TLDR: Go in the 'IT' page, loop through all the rows of Excel that contain the Department: 'IT',

           then switch to HR page, loop through all the rows of Excel that contain the Department: 'HR', and so on

 

 

 

FlashDota_0-1706881605578.png

 

  • ryule Profile Picture
    929 Super User 2024 Season 1 on at

    The below will build a DataTable of unique departments and their counts (my first bunch of steps are just to create a list like your screenshot; obviously you would use your own list). And then you could use that to help determine how many times to loop

     

    Variables.CreateNewList List=> DepartmentList
    Variables.AddItemToList Item: $'''IT''' List: DepartmentList
    Variables.AddItemToList Item: $'''IT''' List: DepartmentList
    Variables.AddItemToList Item: $'''IT''' List: DepartmentList
    Variables.AddItemToList Item: $'''HR''' List: DepartmentList
    Variables.AddItemToList Item: $'''HR''' List: DepartmentList
    Variables.CreateNewDatatable InputTable: { ^['Department', 'Count'], [$'''''', $''''''] } DataTable=> DataTable
    Variables.DeleteRowFromDataTable DataTable: DataTable RowIndex: 0
    LOOP FOREACH CurrentItem IN DepartmentList
    Variables.FindOrReplaceInDataTable.FindItemInDataTableEverywhere DataTable: DataTable AllMatches: True ValueToFind: CurrentItem MatchCase: True MatchEntireCellContents: True DataTableMatches=> DataTableMatches
    IF IsEmpty(DataTableMatches) THEN
    SET DataTable TO DataTable + [CurrentItem, 1]
    ELSE
    SET MatchRow TO DataTableMatches[0][0]
    Text.ToNumber Text: MatchRow Number=> MatchRowNumber
    SET CurrentCount TO DataTable[MatchRowNumber][1]
    Variables.IncreaseVariable Value: CurrentCount IncrementValue: 1
    Variables.ModifyDataTableItem DataTable: DataTable ColumnNameOrIndex: 1 RowIndex: MatchRow Value: CurrentCount
    END
    END

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    What @ryule suggested will do the trick to cover what you have asked. However, assuming you need some unique row data from other columns in your Excel sheet, it might be better to use a different approach.

     

    You could simply store the value of the previous iteration in some temp variable, and then check if the current value is equal to the previous one. If it is, then continue looping in the current page. If it's not - move to the next page.

     

    Somewhat like this:

    # Setting it to an empty value before starting
    SET PreviousValue TO ''
    # Assuming you have your Excel data in a list called ExcelList
    LOOP FOREACH CurrentItem in ExcelList
    IF CurrentItem = PreviousValue THEN
    # Do whatever you need here, considering this is the correct page
    ELSE
    # Either exit the loop and start the next loop later, or move to the different page and then do whatever you want
    END
    SET PreviousValue TO CurrentItem
    END

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 237 Super User 2026 Season 2

#2
David_MA Profile Picture

David_MA 227 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 194

Last 30 days Overall leaderboard