cancel
Showing results for 
Search instead for 
Did you mean: 
manuelstgomes

Power Automate: How to access Excel with a dynamic path

One of the questions I see a LOT in this Forum are issues with accessing Excel files where you provide a dynamic path.

 

TL;DR: Download the template and have your problem fixed in 2 minutes.

 

It works in other actions in Power Automate, so why not here? Well, there’s a limitation in Power Automation that doesn’t allow that. The issue is that the exception is not clear at all, making people question if their Flows are correct or not.

It occurs on OneDrive files as well as SharePoint, so I’ll use OneDrive to demonstrate the issue and the solution.

The issue in detail

Let’s try to access the information in an Excel file. It’s quite straightforward. Just use the “Get a row“ action, and we’re good to go:

small-Screenshot_2020-01-21_at_10_09_26.jpg

So far, so good. So now, to simulate the dynamic path, let’s put the path in a Compose action. It’s the same. We’re passing a path to Excel; we’ll use the same path, the same Excel, the same Table, and the same ID/Column combination.

small-Screenshot_2020-01-21_at_10_11_17.jpg

Running we get:

small-Screenshot_2020-01-21_at_10_11_36.jpg

 

Worse yet the error is quite cryptic:

small-Screenshot_2020-01-21_at_10_11_47.jpg

 

The error itself doesn’t tell us much, but the issue is with the dynamic path since we’re using the same strategy, just building the path before using it. It isn’t stated directly in the official documentation, but there are only three ways to access the file (quoting from the documentation):

  • Pick a file from the file picker.
    -Use output from the OneDrive for Business connector’s triggers/actions (file’s Id or File identifier property depending on which one is present for the particular OneDrive for Business’s action or trigger).
  • Use output from the SharePoint connector’s triggers/actions (file’s Id or Identifier property depending on which one is present for the particular Sharepoint’s action or trigger).

So no dynamic path mentioned. It’s a strange limitation since, if we use the same strategy to access any SharePoint file, we don’t have this issue, but I digress. It’s a limitation, and we have to deal with it. So, how do we deal with it?

 

The Solution

Note Before we go any further, I have a template that you can find in my Template Archive ready for you that you can upload and have all. Use it and use the following information as a reference. I have another article that describes in detail how to call an HTTP triggered Power Automate in case you’re not familiar with that.

 

The solution can look a little bit complex, but I’ll guide you through each step of the process.

 

First, since I use Excels all the time, I decided to build a separate Flow that takes care of this for me. I’ve enclosed all the logic there and, once Microsoft fixes the issue, I need to replace that action with the future action, and that’s it.

 

So let’s look at the steps:

small-Screenshot_2020-01-21_at_10_24_16.jpg

 

Roughly what we’re doing is triggering the Flow with external parameters, fetching the Excel details, and using its ID to get the information. As I mentioned before, accessing an Excel file using an ID is perfectly valid, so let’s use that.

 

The Trigger

The trigger is the most straightforward part of the process. If you’re not familiar with how to call another Flow using an HTTP call, I have an article that explains this in detail.

 

The input is what we would expect:

  1. The path of the file
  2. The table we want to access

small-Screenshot_2020-01-21_at_10_29_10.jpg

Here’s the definition in case you want to build it yourself:

 

 

{
    "type": "object",
    "properties": {
        "path": {
            "type": "string"
        },
        "table": {
            "type": "string"
        }
    }
}

 

 

 

The Tricky Part

Now we have to use the “Send an HTTP request to SharePoint” action. You may be using Power Automate for a while and never had the need to use this action, but it can be quite handy when some of the pre-defined actions don’t cut it. With this action, we can access Sharepoint using the SharePoint’s API. Actions like “Get Item“ for example, use the same API, but they are just abstracting the technical details. In this case, we have to go a little bit deeper, but it’s simple to understand:

 

small-Screenshot_2020-01-21_at_10_32_39.jpg

 

So we’re making a “Get” request to SharePoint to get the information about a file that exists on a particular path. The syntax is the one required by the API, so we’re just providing it and adding the path that we get from the trigger.

 

What do we get in return?

We get what we need — the Excel’s ID. Now we can do a call to Excel to obtain any information we want since the ID is a valid way to call Excel.

small-Screenshot_2020-01-21_at_10_34_37.jpg

 

 

 

@{body('Send_an_HTTP_request_to_SharePoint')?['id']}

 

 

 

Simple right?

 

Let’s get the information we need

I included in this template examples in how to get “Worksheets,” “Tables,” and “Rows” so that, in case you need any of them, you can adapt the template to get that information.

We can call all of them the same way:

small-Screenshot_2020-01-21_at_10_37_51.jpg

 

So now we have the information. All we need to do is to send it back from the Flow.

 

Returning the information

Sending the information back is quite easy. We have a “Response” action that can help us with this.

small-Screenshot_2020-01-21_at_10_40_09.jpg

 

In this template, I used the most restrictive return so that you know how I do it. Since I want to get one row only I’m doing a:

 

 

first(body('List_rows_present_in_a_table')?['value'])

 

 

If you wish to return all of them, remove the “first” and return a JSON with all the information.

 

Making things easier

I’ve built a template that you can find in my Template Archive that is independent of other Flows, so you can import it and use it in multiple Flows. Adapt it any way you like to get the information that you need.

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/