Power Query: Handling Dynamic Arrays
8 March 2023
Welcome to our Power Query blog. This week, I extract data from a Dynamic Array.
I have a list of trainee salespeople that I need to extract to Power Query, so that I can merge their details with another query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image1-1678115334.png/7b1b8842610329a778d58f6ee051dd3b.jpg)
Seems simple enough; I select the data and use ‘From Table/Range’ on the ‘Get & Transform’ section of the data tab:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image2-1678115367.png/47e73c47c97df5c559649e63bda831d1.jpg)
I don’t have any headers, so I take the defaults.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image3-1678115397.png/a8ec9394613a4cbea989ec296805360b.jpg)
The results are not good. If I click on the Error value, I see this:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image4-1678115418.png/dc1854baef0fcb22f6bc7d87a791d7f3.jpg)
If I discard the query and go back to the sheet, I can see what has happened:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image5-1678115444.png/f651a649ac9a7b9336f5cd146b3e234e.jpg)
To get a #SPILL! error, I must be dealing with a Dynamic Array. I use CTRL+ Z to undo the Table creation.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image6-1678115475.png/878cb7433545b513ab19e1b7f32e170b.jpg)
The list has been created using FILTER() which means that the output is a Dynamic Array. Obviously in this example, I can just use the original table, but let’s assume that I don’t have access to that.
I used ‘From Table/Range’ to extract the data, and so Power Query converted the data to a Table, which doesn’t currently work with Dynamic Arrays. I could however create a range.
In the ‘Name Manager’ on the Formulas tab, I can create a new range. If I just select the cells currently populated, this will be incorrect when I have more trainees. I need to create a dynamic range. This is the range I create:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image7-1678115504.png/741288c2ad6bb7cc4e4fa7fb304f1feb.jpg)
The Excel formula is:
=Sheet1!$F$2#
This links to the data in the Dynamic Array created by the formula in cell $F$2. Now, I can create a blank query to access this range:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image8-1678115595.png/22953db8db4b58c7698c557aac1f52f7.jpg)
I create the Source step:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image9-1678115620.png/5103f8990a7d8322bbb0ea5d2be83966.jpg)
The M code is:
= Excel.CurrentWorkbook(){[Name="DR_Trainees"]}[Content]
This extracts the content from the range DR_Trainees in the current workbook.
Power Query generates a ‘Changed Type’ step, which I keep.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image10-1678115684.png/fdd671282e05ab3984f9f3f76d4149df.jpg)
I don’t rename the columns yet, as I want to check that this query will refresh as expected. I use ‘Close & Load’ from the Home tab and create the output on a new sheet:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image11-1678115708.png/cf8862135ab23cad6ff5823bebef504a.jpg)
Now I can add some new trainees to the original table:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image12-1678115730.png/cfc6c9788bfd69b2dd3ffd26a5b15b17.jpg)
The Dynamic Array updates immediately. I refresh theTrainee_list query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image13-1678115757.png/f6fcf322ae3f82d75c12b100e0ce190b.jpg)
The new trainees appear, and my list is complete. I can use Power Query to extract data from a Dynamic Array.
Come back next time for more ways to use Power Query!