If you're just getting started with static data and are importing it from Excel then read my post on this first and then come back.
A simple "List" for Drop Down, List boxes and more
| It *almost* makes sense |
Pick a lane idiot.
You can also do a multi-column source. This is where things start to get "weird"(-er).
Single-column lists are sorta-Collections? (but formatted 100% differently)
In my above screenshot I've used a simple list ["Item1", "Item2", "Item3"]. This is, commonly referred to in general terms a single column of data.If you're an Excel person, imagine the above list of values from first to last residing in A1, A2, A3. That's column A and row 1, 2 & 3. But what if we perhaps want to do a couple of things w/ our list of data and only one of them is having an item shown in a drop down? I want to include A1, B1, A2, B2, A3, & B3! That's where multi-column lists come in and you'll see references to the word "Collections" littered about the PowerApps documentation and forums.
| It looks much easier in Excel |
HOWEVER, what is not clear is that the PowerApps documentation doesn't state what (if anything) the original "single-column" type of "variable" this cobbled together series of characters actually is. Is it a List? A Collection? A Gigglesnort? How can I even search for something online if I don't know what it is called?! It actually is a Collection...eventually.
Essentially Microsoft is making it "easy" on you by giving you a short-hand version of feeding the Items field a single column list of data that the control already knows how to convert into what it needs (i.e. a Collection). However, if you try to take this trick with you and use it elsewhere, you might run into problems.
For example, if you tried to create a "Collection" by assigning a similarly formatted string to a local context variable...
- UpdateContext({myCollection:["Item1","Item2","Item3"]})
It actually comes down to how PowerApps (ultimately) treats Collections. Collections are always global so this means that attempting to put this into a local "context variable" (via UpdateContext) will not work. HOWEVER, you can use what you already know about global variables to do something similar. The following statement would work instead:
- Set (myCollection,["Item1","Item2","Item3"])
There are a few instances of where you still might wind up using the [] notation. One is when you try to use the in Operator.
- If(myField.Text in ["help", "sos"], UpdateContext(popupHelp:true), UpdateContext(popupHelp:false));
- UpdateContext(popupHelp:myField.Text in ["help", "sos"])
Single or multi-column lists are PowerApps variables called "Collections"
The basic commands we use with Collections are outlined here. In most scenarios, using ClearCollect() is the right choice.The classic example that Microsoft leans (heavily) on is populating a Collection from a SharePoint list (although it could come from any linked data source):
That's a function that clears and creates (if necessary) a "Collection" named "MySPCollection" and it gets the data from a SharePoint (or anywhere really) list data source you named "ListName". Everything in that particular list (within reason) gets pulled into a variable inside the application. Again, the data doesn't have to come from SharePoint of course, but it's a common example they give.
NOTE: Doing things this way means that if the SharePoint data changes during that time, your application will not have the current data. Only do this for reasonably static information (e.g. menus, language text, etc.)
So to "create" a Collection identical to my example above, you'd actually have to create it somewhere before you get to your Drop down or List box control. That can be at your application's start, when a user clicks a button, when a screen is shown, etc.
To create an identical Collection to my first example (that has a single column of data), you could use the following command tied to an event (e.g. ScreenVisible, ButtonClick, AppStart, etc.) prior to when you want to use it. For now, drop a Button on your form and change the OnSelect code to be the following:
Hold down the Alt key and click on your button (this runs the above code and creates the Collection).
This results in is the exact same thing as we originally put into our Items field for our Dropdown initially. We could reference that variable name (e.g. myCollection) in a Drop down or List box exactly as before w/o any difference. Alter your Drop down control Items property to be myCollection and everything would appear identically to the original example.
Once you click the button (or load the screen, the app, etc.), the variable gets populated and the list as well. Clicking the button multiple times just clears and reloads the list. You really would only ever need to do this once unless your list changed for some reason.
What you might notice in the second and more exact command above is that we've now created something akin to a JSON (or similar) formatted series of Name/Value pairs. This will become important as we continue below.
HOW DO I CREATE MULTI-VALUE COLLECTIONS?
The first (and working) command creates a collection similar to the first one, but each item/row has two distinct columns tied to it (e.g. Value and Quantity). These names (Value and Quantity) are just made up for this example. These are commonly referred to as "name/value pairs" that you can make up on your own. Just make them relevant/understandable to you.
It is simpler to see how things are clustered if you put the working command above into a field in PowerApps and then click on the Format Text button below your formula. Then the above looks like the following:
ClearCollect(
myNewCollection,
{
Value: "Item1",
Quantity: 10
},
{
Value: "Item2",
Quantity: 200
},
{
Value: "Item3",
Quantity: 0
}
)
That's much easier to read.
Each "row" in the "table" is separated by curly brackets {} while "columns" within the "row" are separated by commas. Rows are also separated by commas between the curly brackets. Notice the complete lack of square brackets anywhere and that what you learned before has zero value.
Thanks PowerApps!
So which column appears inside the control? The good news is that PowerApps is actually slightly smart about this and generally will pick the first column in your Collection as the default value to display.
Change the button code to the above ClearCollection code snippet (note the variable name change for clarity). Now edit your Drop down control so that the Items field points to the new Collection myNewCollection.
| Change the Value field for whatever you want to be visible to the user |
Note that no values will be displayed because you haven't run your code to populate the variable yet. If that's bothering you, hold the Alt button on your keyboard and click the button control you just edited (again, you magically just "ran" this part of your application).
Now look just below the Items field on your Drop down control. There is a field named Value which tells PowerApps which column should appear for users inside your control. By default it is set to "Value" (same as our first column) and shows what that column contains.
Referencing secondary columns (and beyond) of selected items.
The whole reason you used a multi-column list is so that you could reference some other value elsewhere in your application. This is fairly easily done via the Selected (Drop down boxes) or SelectedItems (List box) functions.For Drop down boxes where only one item can be selected it is fairly easy. We could reference "Quantity" in our above example by using:
Again, you would replace the orange text with the name of your control.
Removing Items from a Collection
This would alter the Collection and remove any items from the list where the Quantity name/value pair was <= Zero.
NOTE: The Remove() and RemoveIf() functions directly modify the list you are operating on, vs. the AddColumns() command I detail below.
Gallery controls use Collections as an input
Now that you understand a Collection is just an old school rows/columns table, it makes sense that Gallery controls use the same kind of variable as an input. These fancy-schmansy controls look fairly slick in PowerApps but aren't obvious on how to use them at first glance.| Default links to a sample Collection |
| Every item's image is the hard-coded to the same non-Collection static image. |
Lame.
In such a scenario, if we had imported an image into our application (View | Media | Browse | Open) named SoldOut, then we could select the Image item that was created by default as a part of the Gallery (left side of screen, expand the Gallery control you added to your screen, select the image) and alter its Image setting from the default value of SampleImage to be:
This would mean that for all items that had a non-zero value no image would be displayed but for our last item, that has a Quantity=0, we get the following:
| Where can I fulfill my Item3 fix?! |
Merging or Joining Collections
The results of us running all of these commands winds up giving us a Collection named mergedList that consists of an Email Address (Email), a first name (FirstName), and a last name (LastName):
| Simple? |
But I made it easy on you. What if the two fields were IDENTICALLY NAMED?! So if List1 and List2 actually both had fields named Email? That's where the RenameColumns() function comes in.
NOTE: Microsoft does have an alternate method to allow you to directly reference individual Datasources/Collections (e.g. List1.Email & List2.Email) via the As operator.
Now normally, I'd tell you how to do this wrong and then correct you for taking the obvious path. But sometimes I'm lazy. Just know that the functions RenameColumns, AddColumns, DropColumns, and ShowColumns DO NOT ACTUALLY MODIFY THE TABLE YOU GIVE IT!!! So AddColumns(myTable...) doesn't modify myTable. It returns a temporary table as an output that contains the modification that results from you running any of these functions.
Maybe I'll do another blog post on this because it will trip you up many MANY times.
Ultimately, the final chunk of code in the above scenario for identically named Email fields looks like:
Copying SharePoint data: DropColumns vs. ShowColumns
Merging Collections into Strings
The results of this would be a variable named csvEmails that contains: test@Test.tst,test2@test.tst
This makes it easy for you to drop in a multi-select combobox and still support your original data fields in SharePoint or otherwise w/ a formatted string. Sometimes this is a good compromise per readability vs. the more structured JSON string.
Turning/Merging simple CSV lists BACK into Collections
- lunchPeople = Janice, Uday, Xiao
- lunchOrdlers = PB&J, Fish, Tofu
![]() |
| I hope there isn't a mixup |
Updating Values in a Collection
This sure looks/feels a lot like JSON
Collections can be easily converted into JSON using the JSON() function. However, at present you cannot do the reverse and import JSON directly into PowerApps and convert it to a Collection without a mildly annoying amount of work. You CAN read/process JSON more easily (if you know me then you know how funny that last word was) in Power Automate. So if you need to process something that is encoded JSON, just know that you can hack your way via that tool into putting it into a more structured data store (i.e. SharePoint List or similar) which can then be read into PowerApps.
One trick that you would be surprised works is that you can use the Set() command to actually directly assign it a static blob of JSON and it will work so long as you put it all inside a string, using double quotes, and convert all double quotes to singles inside of the JSON. However, this must be hard coded. You cannot look this up from elsewhere (e.g. SharePoint). This is because Collections must be defined at design time. You cannot dynamically add new columns that will be created from the source. Also, the language gets a little confused as you try to access values within the JSON that are Collections/Lists themselves. So while it works, it is of limited use. Just a curious thing the platform almost does.
NOTE: If you caught it, I did kind of lie to you near the beginning of the article on the Set() command not being able to create multi column lists. It can, but the use case is funky and extremely limited. YMMV
Final thoughts
PowerApps isn't really designed to have hard-coded data mainly because that's just bad practice programming-wise. However, sometimes you want to test some things and just see how everything functions before you pull in outside data. When you do this, sometimes PowerApps is...annoying.
There are certainly use-cases for importing semi-static data (e.g. Excel tables) that a field team might work with and update while they are "offline" which they then later want to submit back to "something" to save the changes. Since so many organizations are starting from some fairly elaborate Excel files, it is reasonable to understand that at some point you're going to pull in an Excel table and have to deal w/ a Collection as outlined above.
NOTE: There now (Dec-2019) exists a method to read/write in real-time to Excel files that exist on OneDrive. Just because you can do a thing...
Sometimes the best thing you can do is to drop in a Data Table control, link it to your Collection, Display the Columns, and review the Collection's contents to ensure you have the data you think you have. Other times, the quick view in the expanded code window drop down at the top of the screen is enough.
You can allow SharePoint and other data sources to create Collections for you automatically, but doing this manually a few times will help you understand what is going on when these things just...don't...work.
When that happens, you might need to figure these things out very quickly and on a live environment. So playing with manual population is worth considering to expand your knowledge.
See Microsoft's documentation for more (or less) about Collections.

Thanks for this blog.
ReplyDeleteHopefully it helps. I write a lot of this down after I've wasted time researching/trying something and try to document it for my future-self (and I suppose others as well). :D
Deleteawesome post. wish I'd read this a week ago!
ReplyDeleteStill more to do here. I've been thinking about doing a SQL -> PowerApps walkthrough on some JOIN/WHERE statements and how those translate into Collection functions. But glad it helped.
DeleteGreat posts John, thanks very much! Nicely laid out and easy to follow structure.
ReplyDeleteYour style reminds me of my old buddy from from the time Steve Jobs was trying to get his Next computer project off the ground. She was trialing it out. Uh, oh...