Skip to main content
Community site session details

Community site session details

Session Id : Y/KQB3f8G36eHTs6/aZL+l
Power Automate - Power Automate Desktop
Answered

Loop Index is Invalid

Like (0) ShareShare
ReportReport
Posted on 14 Jan 2024 18:11:36 by 39

I seem to be having this issue for the past few days. I was asked by my mentor to create a workflow that could be used for retrieving currency exchange values from a website and write them down in Excel. I used a Loop, but I was advised to use a For Each action instead. 

 

However, I seem to be encountering this error, wherein the CurrentItem in For Each is declared invalid whenever I try to execute the workflow. 

 

I keep getting this in the error: Correlation Id: 28932dba-2fa8-4602-90d1-c2f748017aa5

 

Following screenshots have been provided for reference.

 

Any tips and advice will be highly appreciated. 

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on 16 Jan 2024 at 13:52:25
    Re: Loop Index is Invalid

    I would assume this might be because your Read from Excel worksheet probably includes the one last row at the end, too. It might for some reason "think" it's not empty - maybe it had data previously and has some formatting stored there, that has not been cleared properly. Try deleting the row from Excel completely and then run it to see if this helps. Otherwise, add an If statement inside your loop to check if %CurrentITem['Value']% is empty. If it is, use Next loop to skip further actions for this row, or Exit loop to stop looping.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • aSagCoder Profile Picture
    39 on 16 Jan 2024 at 10:19:00
    Re: Loop Index is Invalid

    Thanks for this! This works, for the most part. I just encountered a tiny issue - when I tried to implement the new variable for the existing rows, it repeats for the last row and then, adds an additional value to the Excel worksheet. Can you help me figure out why it is doing so and how can I fix it?

    aSagCoder_0-1705400130628.png

    Here's the workflow for reference - 

    aSagCoder_1-1705400270467.png

     

    I tried using %nbrrowindex - 1%, but this causes it to overwrite the column header with the extracted numeric value instead. How can I avoid that?

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on 16 Jan 2024 at 09:17:58
    Re: Loop Index is Invalid

    %FirstFreeRow% is a thing that makes sense when you want to append new rows to a table. But you want to write data to existing rows, so that won't work.

     

    Instead, you will need to implement a loop index. Use Set variable before your loop and set an index to 2 (that's the row where your data starts). Then use that variable as the row index in Write to Excel worksheet. And then use Increase variable at the end of the loop to increase it by 1.

     

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • aSagCoder Profile Picture
    39 on 16 Jan 2024 at 09:04:37
    Re: Loop Index is Invalid

    Yeah, but I actually want to write the numResultList in a specified column range - however, what I used for it isn't working anymore. 

     

    aSagCoder_0-1705395721572.png

    Initially I was using CurrentItem but that was invalid, as Row required a numerical value. So I tried using FirstFreeRow - but that doesn't seem to be working either. 

     

    This is the Excel worksheet I am using, and I wish to write the result extracted in the D column. What can I do in the Write to Excel action to fix this issue?

    aSagCoder_1-1705395816899.png

     

  • opit Profile Picture
    160 on 15 Jan 2024 at 19:37:39
    Re: Loop Index is Invalid

    the action write to excel has nothing to do with CurrentItem. It writes to excel values got of element on web page.

    see bellow yellow:

    opit_0-1705347374167.png

     

    you need to specify more detail your problem?

  • aSagCoder Profile Picture
    39 on 15 Jan 2024 at 19:28:34
    Re: Loop Index is Invalid

    Hi, sorry to bother you again - but the Write to Excel function is not working and using CurrentItem doesn't working as this action requires a number. How can I fix it?

  • aSagCoder Profile Picture
    39 on 15 Jan 2024 at 19:15:44
    Re: Loop Index is Invalid

    That actually worked! Thank you so much for the help! ❤️

  • Verified answer
    opit Profile Picture
    160 on 14 Jan 2024 at 19:27:52
    Re: Loop Index is Invalid

    @aSagCoder 

    opit_0-1705260450857.png

     

    you need to use: %currentItem[colum name or number]% and then you get value automatically

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Loading complete