PowerApps – using Checkbox controls with Multi-Valued Choice columns

2+

At some point Microsoft PowerApps Team added support for fields with multiple values through a Combo Box control. However, as of this moment (2/3/2019) there is still no native support for Checkbox controls even when you configure your Choice column in SharePoint to have Checkboxes (allow multiple selections).

There is a good article (https://powerapps.microsoft.com/en-us/blog/multivaluedchoicesinforms/) published by Carlos Figueira from PowerApps Team that shows how to implement Checkbox controls. The downside of it was using a Text column that imitates a Choice column.

It’s been a while since that article was published, so it’s hard to say if anyone has done it differently.


In this post I will explain how to pair Checkbox controls with a true Multi-Valued Choice column.

Please note, in my example I will be using a PowerApps Form rather than PowerApps App; however, it shouldn’t make any difference.

Let’s create a SharePoint List, name it TestList, add a TestListColors Choice column. Red, Green, Blue are the values; Checkboxes (allow multiple selections) is selected.

Here is how it looks with a test1 item:

Next, we use a PowerAppsCustomize forms action to create a default PowerApps Form automatically:

Just like in the article above we need to remove a Combo Box control from the TestListColors Data Card, then add three Checkbox controls – Checkbox1 (Text value – Red), Checkbox2 (Text value – Green), Checkbox3 (Text value – Blue). Don’t forget to clear some minor errors after the Combo Box has been removed as there are always some dependencies.

There are basically 2 steps that we need to take care of:

  • saving data when checkboxes are selected;
  • loading and displaying correct checkboxes when reading previously saved data.

STEP 1 – SAVING DATA

For each Checkbox we need to change both OnCheck and OnUncheck values, they are all the same:

ClearCollect(
	SelectedColors,
		If(Checkbox1.Value,"Red"),
		If(Checkbox2.Value,"Green"),
		If(Checkbox3.Value,"Blue")
);
ClearCollect(
	SelectedColors,Filter(
		SelectedColors,
		!IsBlank(Value)
	)
)

What it does is when checking or unchecking the checkboxes it updates a collection. It also removes blank values.

The Update field for the TestListColors_DataCard1 needs to be:

SelectedColors.Value

STEP 2 – LOADING AND DISPLAYING DATA

A Default value for each Checkbox:

If(
	{
		'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
		Id: 0,
		Value: "Red"
	} in TestListColors_DataCard1.Default,
	true,
	false
)

Note, that Id and Value in the code above have to match a corresponding Checkbox.


RESULT 

2+

This Post Has 61 Comments

  1. Bill

    Pavel – Great post! This is exactly what I need in my current form. I am having trouble with 2 things in your post:

    1. What do I set the “Update” property to in the Datacard that held my combobox that now holds my checkboxes?
    2. I do not understand this part of your code:

    );
    ClearCollect(
    SelectedColors,Filter(
    SelectedColors,
    !IsBlank(Value)
    )
    )

    I believe this would be used on the OnUnCheck property. This looks like on UnCheck I will be clearing the entire collection. Does each checkbox write to its own collection? If not, if I uncheck the Red box…wouldn’t I be clearing the entire collection? Obviously I’m not understanding something here. 🙂

    Any help would be greatly appreciated.

    Bill

    0
    1. Pavel Bludov

      Hi Bill,
      Thanks for the kind words!
      1) Looks like “Update” should be YourCollection.Value
      2) That very part takes care of blank values (when a checkbox is not selected). If you don’t use it, then you collection will have values {Red”, “Blue”, “”} (you don’t really want to try to save that last one “”).
      The code is exactly the same for both OnCheck and OnUncheck.
      If more questions, don’t hesitate to contact me.

      0
  2. Bill

    Thanks Pavel! I now have the data saving back to my SharePoint list (I’m using a PowerApp App) but am struggling with the Loading and Displaying Data step. What does Id refer to in the below?

    If(
    {
    ‘@odata.type’: “#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference”,
    Id: 0,
    Value: “Red”
    } in TestListColors_DataCard1.Default,
    true,
    false
    )

    0
    1. Pavel Bludov

      Bill,
      If your multi-choice field has Red, Green, Blue values then Red would be Id: 0, Green would be Id: 1, Blue would be Id:2.
      So each check box should have its own code similar to that.
      It’s somewhat hard-coding but shouldn’t be an issue if the data/purpose of the form doesn’t change often.
      Thanks!

      0
  3. Bill

    Do you know where can I find out what Id is associated to each checkbox?

    0
    1. Pavel Bludov

      As an example,
      If your Checkbox1 is dedicated to Red color, then its code should have Id: 0.
      If your Checkbox2 is dedicated to Green color, then its code should have Id: 1. And so on.
      The association is made by you.

      0
  4. Bill

    I have it working now! This is a great way to use checkboxes with multi-valued choice columns. I’m assuming that Id’s are assigned for each checkbox I put into my Datacard automatically by PowerApps. And I’m assuming the Id values start at 0 and progress. So if I have 5 checkboxes, my Id values will be 0, 1, 2,3 and 4. If I have 10 checkboxes, it will be 0,…9. Thanks again Pavel.

    0
    1. Pavel Bludov

      Yep, that’s it!
      Though IDs are not about the number of checkboxes, they must match the IDs of possible values in a multi-choice column.
      I can have just 2 checkboxes:
      Checkbox1 (for Red color) – Id: 0
      Checkbox2 (for Blue color) – Id: 2
      Note how I skipped Green value with its Id: 1
      Hope it makes sense.

      0
  5. Anthony Walker

    This is fantastic, many thanks. However, there seems to be a problem with caching. When a selection is made when editing a form, you either have to open another list item or refresh the browser otherwise if you open the item you just edited without doing that, it doesn’t show the edits. Have you got the same problem with this?

    0
    1. Pavel Bludov

      Hi Anthony,
      You are welcome and thanks for the kind words!
      Yes, that sounds so familiar and reminds of some pain.
      First, please check if this option is on for you and turn it off if it is – go to “File” – “App Settings” – “Advanced settings” – make sure this experimental feature is off “Use longer data cache timeout and background refresh”.
      That option was screwing me up when I was trying to open the item that I have just submitted. Now, this is important, it was only affecting a previously submitted item, not the rest of them.
      If that’s the problem, then it’s not related to Checkboxes. It can happen in any form.

      0
      1. Ram

        I am applying same approach for days of work where days from Monday to Friday able to be selected . Any clues for working out this.
        Thanks

        0
  6. Ram

    How can apply same approach for days of work where use able select the days.

    0
    1. Pavel Bludov

      Hi Ram,
      What is not working for you? Monday through Sunday are just text values. Just replace “Red” and other colors from my example with your 7 days. If I’m missing something, please let me know.
      Thanks!

      0
  7. Jessa

    Hi,
    I did exactly the provided solution, however the data is not being saved into the Sharepoint list linked to my Powerapps form.

    0
  8. Jessa

    Hi,

    I followed the solution, it’s not being recorded to the sharepoint list though.

    0
    1. Pavel Bludov

      Hi Jessa,
      Sorry for not getting back earlier. I replied to your email.
      Thanks!

      0
  9. Justin

    Hi Pavel!
    This article is amazing! I was able to successfully SAVE and LOAD the multiple checkbox values to my SharePoint List using your method. But I’m running into an issue that I’m wondering if you can help?

    For some reason, as soon as I used this method, it won’t display any records anymore (in View mode). When I click any record in the SharePoint List, it only loads the first record on the list. If I click the newest record or any other record, it still only displays the first record. Even after doing a hard refresh, the form doesn’t seem to refresh and show any other records, it only displays and allows editing the first record.

    Would you know why that happens?
    When I remove all the code from your article, it successfully displays any record again. So something in the code is preventing it from displaying the records.

    0
    1. Pavel Bludov

      Hi Justin,
      Glad I could help with my blog.
      First, please check if this option is on for you and turn it off if it is – go to “File” – “App Settings” – “Advanced settings” – make sure this experimental feature is off “Use longer data cache timeout and background refresh”. That setting is per application I believe.
      Please let me know.

      0
      1. Justin

        Hi Pavel,
        Thanks for your quick response. Unfortunately, that didn’t work. Now it seems even if I remove the checkboxes, the issue still happens. It only gets fixed if I go to ‘See all versions’ and restore an older version.

        I noticed this code in the Form’s “Item” field that was put there by default:
        If(IsBlank(SharePointIntegration.Selected) || IsEmpty(SharePointIntegration.Selected),First(Requests_Test),SharePointIntegration.Selected)

        So I’m guessing for some reason, after implementing the method in your article – it’s seeing the selected SharePoint List item as blank or empty, therefore only showing the first record?

        It’s very strange because it’s saving all new items fine with the checkbox values. So I’m really confused why it’s not seeing any of the selected items given that your code doesn’t touch that?

        0
        1. Pavel Bludov

          Replied through email. Thanks!

          0
          1. Casil Jomar

            I am encountering this issue also. 🙁

            0
          2. Pavel Bludov

            Hello Casil,
            What Justin did he created a new site/collection and everything worked once he went through my example. I’d say it might save you some headache if you create a test collection from scratch and see if everything works fine. That would be a good starting point.
            Stay safe!

            0
        2. Jeseena

          Hi ,

          I’m sure you must have found a solution for this. I am facing the same issue.if you have fixed it, could you please reply back

          0
  10. Dhruv Mathur

    Hi Pavel,

    I followed your example and it worked like a charm. I have a form that has four choice fields that require multiple selections, and I was looking for a way to handle the multiple selections. This will work great, I can see.

    0
    1. Pavel Bludov

      Hello Dhruv,
      Happy I could help!

      0
  11. Avanika

    Thanks for this. It was exactly what i needed. But i am facing an issue – when i check a checkbox and then uncheck it before submitting the form, it still takes the checked value. I did put this on Uncheck property of all the checkboxes – ClearCollect(
    SelectedCategory,Filter(
    SelectedCategory,
    !IsBlank(Value)
    )
    )
    Any ideas what could be wrong?

    0
    1. Pavel Bludov

      Hey, glad I could help!
      It looks like you are missing some code, it is the same for Uncheck and Check properties:
      ClearCollect(
      SelectedColors,
      If(Checkbox1.Value,”Red”),
      If(Checkbox2.Value,”Green”),
      If(Checkbox3.Value,”Blue”)
      );
      ClearCollect(
      SelectedColors,Filter(
      SelectedColors,
      !IsBlank(Value)
      )
      )

      where number and code of If statements will depend on your application/form.
      Without the full code I have above all your Uncheck action does is just removes blank values thus keeping all checked values within your collection.

      0
  12. Avanika

    Awesome. Thanks for such a quick reply. Really appreciate it. it works perfect now!

    1+
  13. Mellissa Perez

    Hi Pavel. Love what I have seen so far. I am trying to adjust your coding to my data and it ran into trouble updating the Default property.

    If(
    {
    ‘@odata.type’: “#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference”,
    Id: 0,
    Value: “ILT”
    } in ‘Delivery Method_DataCard1’.Default,
    true,
    false
    )

    For the DataCard1.Default line I get an error “Invalid argument type. Cannot use Record values in this context”. Would you have any ideas?

    Thank you!

    0
    1. Pavel Bludov

      Hi Mellissa,
      What is the type of your column that holds “ILT” value? Also, can you list all values from it?
      Sending you an email just in case.
      Thanks!

      0
  14. Viktor

    Hi Pavel,

    Seems like I am having the same issue as Meliissa. I deleted my combo box and followed all you instructions; however, a card is complaining over “.Value” “Expected Record Value.” All my combo boxes have .Default underlined in the formula for the Default that you provided. Have been struggling for 2 days and was not able to figure out on my own.

    0
    1. Pavel Bludov

      Hi Viktor,
      I’ll have to double check if I have such an issue with a newly created list / app. My existing app didn’t have that problem even after updating the version of the app.

      0
      1. Viktor

        Thanks Pavel!
        On my card card the “Update”= SelectedColors.Value is underlined red saying that “Expected Record Value” and every single combobox has “.Default” underlined showing “Invalid argument type. Cannot use Record values in this context. I even tried to submit, but no values are being recorded in SharePoint.

        Appreciate your help!

        0
      2. Viktor

        Hi Pavel,

        Just wonder whether you were able to re-create my use case with the same issue. Thanks!

        0
        1. Pavel Bludov

          Sorry, been very busy but I’ll try it tonight. Will let you know.

          0
        2. Pavel Bludov

          Viktor,
          Created one from scratch, took only a few minutes, worked like a charm.

          0
  15. Nagul

    HI i want Update ….two choice Columns in list using UpdateIf Finction…i am able to update Singale Column…but i need to update two Choice Filed…Can aby one suggest.

    UpdateIf(FA_NewRequest_List_1,ID =DocID,
    {
    Status: {‘@odata.type’:”#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference”,
    Id:0,
    Value:”Pending Approval from MD”}
    });

    0
    1. Pavel Bludov

      Hello Nagul,
      I think it’s possible but can you please give more info on how it’s going to work, just the concept and what should happen and when.
      Thanks!

      0
  16. Tej

    HI Pavel,

    i tried above step selection was working fine in power Apps canvas design.But unable load data from list to checked box default value.

    If(
    {
    ‘@odata.type’: “#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference”,
    Id: 0,
    Value: “EmailValue”
    } in Checkbox2_1.Default,true,
    false
    )

    0
    1. Pavel Bludov

      Hi Tej,
      I think you have it wrong in “Checkbox2_1.Default”. It should be “DataCardNameHere.Default”.
      Try that and please let me know.
      Also make sure your “EmailValue” is truly the 1st value in the column.
      Thanks!

      0
  17. Tejesh

    Thanks for your prompt response.
    My data card name is txtEMAIL_2 and my datacard other label also there along with check box.if I use txtEMAIL_2.Default,I am getting error at default (Name isn’t valid.This identifier isn’t recognized)

    0
    1. Pavel Bludov

      Hey Tej,
      It’s not supposed to show any error messages because DataCardNameHere.Default should have a value similar to this ThisItem.’Name Of Your Choice Column’ (multi-choice column). If you used the original datacard that comes with and didn’t create one from scratch then there shouldn’t be any problems. If still issues, please reply to my email with screenshots (from sharepoint to see the properties of that column and from powerapps).
      Thanks!

      0
  18. chanvit

    Hi,
    This worked perfectly, but when I go to edit/view data that has already been created, the checkboxes no longer show what had been selected previously. Any thoughts?

    Thanks in advance.
    Chanvit

    0
    1. Pavel Bludov

      Hi Chanvit,
      The “STEP 2 – LOADING AND DISPLAYING DATA” code in my post is the only responsible for showing checkboxes correctly selected when viewing/editing an entry.
      If still the same, I would need some screenshots to take a loot at.
      Replying to your email in case you need to send those.
      Thanks!

      0
  19. Chanvit

    Hi Pavel,

    Thanks for getting back to me so quickly on this, I really appreciate it. I figured it out, there were some typo errors on my end, so it’s working fine now. Keep up the good work.

    Regards,
    Chanvit

    0
    1. Pavel Bludov

      I’m glad you got it working, Chanvit!
      Stay safe!

      0
  20. Ferhat

    Hello, First, tanks for sharing! I am new. I am trying to create a form with several check boxes. I followed all the steps. I have a red when I do: SelectedColors. did you create something : SelectedColors
    Could you help me please.

    0
    1. Pavel Bludov

      Hello Ferhat!
      The only place where SelectedColors collection is calculated is within each checkbox. Nowhere else.
      Let me know if still no success.
      Stay healthy!

      0
  21. Ferhat

    Hello Pavel,
    Thank you for your reply. yes, finally it is a collection. It works well, but when I want to change the boxes, changed. It just takes what I selected at the start. It doesn’t want to make the changes.

    0
    1. Pavel Bludov

      Ferhat,
      Please double check all 3 areas:
      Step 1 is done for each Checkbox for both OnCheck and OnUncheck properties;
      Step 1 also has a different value for Update property of your datacard;
      Step 2 is done for a Default property of each Checkbox and is unique for each one of them.
      Thanks!

      0
  22. Chanvit

    Hi Pavel,

    I’ve setup my form with the checkboxes per your instructions and all was working well until I go to an entry in that form and make an update to another field (not the checkbox). Once I save the form after making the changes, I noticed that the checkbox selections have disappeared… Any ideas what could be causing this?

    Thanks in advanced for your help with this.

    Regards,
    Chanvit

    0
    1. Pavel Bludov

      Hi Chanvit,
      Are you using your business application or my example?
      If not the latter, I would recommend creating one on a side and testing it. It should only take about 10 min or so to create one. Everything should be working fine.

      0
      1. Chanvit

        Hi Pavel,

        Thanks for getting back to me on this. I’m using a business application that I developed, with the form element based on your instructions. I’ll try re-creating your example and see if I missed anything. It’s weird because everything works, until I make an edit to a different field and try saving the form, that’s when the check-box choices disappear. Anyway, let me give it a try.

        1+
  23. Dhiren

    It works like a charm but i have only one issue as when in edit form i tried to submit again it gives error message for required field even my checkbox is showing as selected and again i have to uncheck and check the box than i have to submit

    0
    1. Pavel Bludov

      Hi Dhiren,
      Sorry for the late reply. You are not using any extra variables anywhere other than that collection variable, right?
      Also make sure this option is off for your tenant – go to “File” – “App Settings” – “Advanced settings” – “Use longer data cache timeout and background refresh” is off. I believe it’s an experimental feature or at least was.
      Thanks!

      1+
  24. Sully

    In the OnCheck and OnUnCheck entries, where does the term “SelectedColors” comes from?! I’ve looked over this thing countless times and can’t see anything that would properly relate to “SelectedColors.” The term just comes from nowhere and then not referenced again. Is it just something that is made up there and doesn’t matter or does it have to correlate to a specific term, list, column, Form Name?! I just add the exclamation marks because I’ve seen it done in another post with no guidance. I’m in crunch-time on a project so I hope you are able to respond. Thank you for this. I can follow everything else, it is just that surprise “SelectedColors” that is throwing me off.

    0
    1. Pavel Bludov

      Hi Sully,
      SelectedColors is just a name of the collection. It is (re)calculated when you check/uncheck boxes. It could be any name, in my example it kind of made sense to name it that way. Hope it helps!
      Thanks!

      0
  25. Sully

    Awesome that you got back to me so quick. Thank you.
    However, I continue to get errors when entering the information in the “OnCheck” and “OnUnCheck.” I’m using Power Apps online to customize a SharePoint Online form. When I click on “edit in the formula bar” for the DataCard, it takes me to the “Update” and shows what I used in place of your input “SelectedSymptoms.” For the other errors, especially for the “OnCheck”/”OnUnCheck,” they keep saying that it is likely due to referencing a control that you’ve deleted.” One other thing, I still have the standard field for my MultiChoice column. Do I just delete that? You reference what to do with it in your post, but I haven’t been able to find the proper way to do that. Thank you again so much for your help and response.
    Below is what I have written out, and there is a red line under all of it which indicates an error.
    ClearCollect(
    SelectedSymptoms,
    If(Checkbox1.Value,”Cough”),
    If(Checkbox2.Value,”Difficulty breathing/Shortness of breath”),
    If(Checkbox3.Value,”Muscle aches”),
    If(Checkbox5.Value,”Fever”),
    If(Checkbox6.Value,”Sore throat”),
    If(Checkbox7.Value,”Abdominal discomfort”),
    If(Checkbox8.Value,”No Symptoms”),
    );
    ClearCollect(
    SelectedSymptoms,Filter(
    SelectedSymptoms,
    !IsBlank(Value)
    )
    )

    0
    1. Pavel Bludov

      Sully,
      1) If(Checkbox8.Value,”No Symptoms”), – this should not have a comma at the end of it. The code shouldn’t have any errors related to the name of the collection because this is how you calculate its value/collection. It can be any new name.
      2) Yes, you can just delete your old Combo Box. Once you do that though, you will have some minor errors to fix. That is because some properties (related to positioning mostly) reference that old Combo Box.
      Thanks!

      0
  26. Dhiren

    Hi Pavel,

    Thanks for the reply Yes i am not using any extra variable even i don’t have collection. I am just customizing my sharepoint form with power app and not creating a app that why i don’t see this setting in my form “File” – “App Settings” – “Advanced settings” – “Use longer data cache timeout and background refresh”. In my edit form checkbox is showing checked but value is false once i unchecked and check again value became true. Not sure what’s the issue? Any help is appreciated also my problem is exactly same described here https://powerusers.microsoft.com/t5/Building-Power-Apps/Checkboxes-checked-by-default-return-quot-false-quot/td-p/53204

    0
    1. Pavel Bludov

      Yeah, you are right, scratch that menu option – it is no longer there.
      Let’s see what people say and if they experience the same issue.

      0

Leave a Reply