Using Excel to access Arcgis online (automated)

18844
36
Jump to solution
03-25-2018 03:33 AM
Jean-YvesLandry1
Occasional Contributor

Wondering how others have used Excel with Arcgis Online, since this is a common query from clients.  I've been using Power Query ( see this excellent walk through) wth Arcgis and it's very easy to setup.  

Thanks,

36 Replies
MartinPerez
New Contributor II

Hi!

 

There are some forums that request you to show some sort of research and effort to solve your issue before asking for help. So, this is what I tried; that worked, but I understand it is not an efficient way to do it. Please bear in mind that this is my first experience with Excel Power Query :O)

 

  1. I modified the first data acquisition query to include my intended Where Clause as:

 

//Custom Variables

.

.

whereClause = "some_field is not null",

//(remember that I skipped the table creations, so I needed to include here the actual values)

 

  1. I added &orderByFields=objectid before &returnGeometry=false in the Source clause:

 

   Source = Json.Document(Web.Contents(fsURL&"query?where="&whereClause&"&outFields="&fieldsOut&"&orderByFields=objectid&returnGeometry=false&f=pjson&token="&token),65001),

 

  1. I created a new blank query and copied the first one into it, and made the following modification:

 

whereClause = “some_field is not null and objectid > 55000“,

 

This is because I looked for the last objectid from the first query, remember that it is ordered by objectid. This created another worksheet with the next 10,000 block of data.

 

  1. Repeated the stetp 3. six more times to get the over 60,000 points I were interested in. So I ended with seven worksheets with all the data scattered.

 

  1. Went to Query tab of the Ribbon (shown when selecting any cell of a queried table) and selected Append, Three or more tables, and selected all these queries:

 

While selecting a Query, From Ribbon select Query, select Three or more tables radio, and Add to Tables to apped; then Ok.

 

This created the Append1 query you can see in the list; and it worked quite well for my experience with Power Query.

 

  1. I deleted the worksheets with the fragmented data, and left only the new one with all the data collected together. This changed all these queries to Connection only:

 

Screenshot of the Show Queries pannel to show queries changed to Connection only.

 

  1. Improved this process a little, by querying the objectids into a table, and using these values for the where clause of all other queries, to “automate” it a little more.

 

I ran your original process changing the where clause to:

 

whereClause = "worked_by is not null",

 

and adding &orderByFields=objectid&returnIdsOnly=true to the source line:

 

   Source = Json.Document(Web.Contents(fsURL&"query?where="&whereClause&"&outFields="&fieldsOut&"&orderByFields=objectid&returnIdsOnly=true&returnGeometry=false&f=pjson&token="&token),65001),

 

then converted into table and drilled down etc. etc. etc.

 

  1. I then used this new table to address the query limit thresholds as:

 

let

//Custom Variables

Query7=Excel.CurrentWorkbook()

{[Name="Query7"]}[Content],

objectid = Number.ToText(Query7{9999}[Objectid]),

 

whereClause = "worked_by is not null and objectid > ",

 

   Source = Json.Document(Web.Contents(fsURL&"query?where="&whereClause&objectid&"&outFields="&fieldsOut&"&orderByFields=objectid&returnGeometry=false&f=pjson&token="&token),65001),

 

for the second query.

 

Then:

 

objectid = Number.ToText(Query7{19999}[Objectid]),

objectid = Number.ToText(Query7{29999}[Objectid]),

objectid = Number.ToText(Query7{39999}[Objectid]),

objectid = Number.ToText(Query7{49999}[Objectid]),

objectid = Number.ToText(Query7{59999}[Objectid]),

 

for the remaining queries (two to six, respectively, as the first and second ones where already correctly configured). I have a Query0 because I implemented the whereClause = “some_field is not null and objectid > 55000“, as my first query, and missed the first 10,000 points where objectid > was not needed.

 

Now, I only need to refresh the objecids query, and then the Append1 query to gather all the data at once. Again, not efficient, but working :O)

 

So, what when my data layer increases over 100,000 features, or over 200,000? Do I create another four, five, ten more queries and append them all? I don’t think so. But looping around in Power Query seems a scary thing, as Power Query is not a conventional programming language, and remember that this is my first experience with it. Any help will be greatly appreciated.

 

Best regards

0 Kudos
Jean-YvesLandry2
New Contributor II

Hi Martin, 

I'm not convinced I understand what you're trying to accomplish, but if I understand correctly you have an issue on the maximum records you can query?

Have you tried modifying your maxRecordCount parameter?  

How To: Update the maximum record count for feature services in ArcGIS Online 

MartinPerez
New Contributor II

Hello There!

Thanks for taking care.

I am not the administrator to perform such a change; I am just an end user,

without ArcMAP. We just get the data and prepare some statistics and

graphics.

The layer has over 60,000 features we are interested in (from nearly half a

million), and I can only query 10,000 features at a time. So, I thought

that a loop would do the trick, but it seems that this is not the case with

Power Query (I think a loop can easily be configured in Python from ArcMAP,

but ...).

I am actually good with the explained approach, and I just need to add a

new query from time to time; so it is not a big deal. I am pretty happy

with your tutorial on how to access the data; I was just looking for some

efficiency improvement.

Best regards,

0 Kudos
ToryChristensen
New Contributor III

Hi Martin,

Don't worry about my previous email, i have worked out the process and it is operational!

Thanks for all your help, this is definitely a game changer for my work!

0 Kudos
MartinPerez
New Contributor II

WHOA Tory!  that is really cool to know; I am so glad you can use it.  These days working from home is quite common, and this may help a lot.  Please take care you all.

0 Kudos
JamesWilson2
New Contributor III

GDay Martin,

Did you ever find a solution to pagination? There is a youtube video we managed to follow here which works: How to do Pagination without knowing the number of pages (Part 2) in Power Query | List.Generate - Y... 

The problem we are now having is that the token fails intermittently, so when we expect 180K records we may get 40K, or 120K, or 180K. Anyone know why the token could be dropping out on us?

0 Kudos
ToryChristensen
New Contributor III

Exciting News Martin! 

I have got the script to work and it is providing the table of attributes as hoped:

The only issue now is when i go to 'Close & Load' i am getting the error message 'Download failed' with no detail. Even though its showing all the rows for the survey.

If there's any advice you have for this step it would be great. Thanks so much for all your help, it has been much appreciated!