cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
audrieg
Level 10

Count the Number of Selected Items in a List Box

Is it possible to count the number of selected items in a list box?

 

I have tried this but it throws an error:

CountIf(IsEmpty(MultiSelectList.SelectedItems)),"0",MultiSelectList.SelectedItems)

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Count the Number of Selected Items in a List Box

You can use the CountRows function to get that number:

 

CountRows(ListBox1.SelectedItems)

8 REPLIES 8
Super User
Super User

Re: Count the Number of Selected Items in a List Box

Hi

 

CountIf(Table, LogicalFormula)

- I look at you case, the MultiSelectList,SelectedItems is Not a Condition, so, nothing would be filtered and counter.

 

Hope I am not out of your question!.

 

NB:

BTW, I had replied to another thread on your Q about LookUp couple of days ago. Please check if it helps.

hpkeong
audrieg
Level 10

Re: Count the Number of Selected Items in a List Box

Thank you for your response.

 

Wouldn't the IsEmpty be a condition?

 

Is this closer? (still gives an error message):

CountIf(ListBoxControlName, ListBoxControlName.SelectedItems<>0)

PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Count the Number of Selected Items in a List Box

You can use the CountRows function to get that number:

 

CountRows(ListBox1.SelectedItems)

audrieg
Level 10

Re: Count the Number of Selected Items in a List Box

I have just fallen in love with you! (Although I feel kinda dumb to not have thought of them as rows-LOL).

 

Last question: Do you know how to clear the selection in the list box?

 

THANK SO VERY MUCH!!

Super User
Super User

Re: Count the Number of Selected Items in a List Box

Hi

 

CountRows is right.

I was looking at your original formula and thought you know CountRows, which is straightforward.

For CountIf(Table, Condition) .. condition must be set.

 

Anyway, things are solved. Enjoy!

hpkeong
Super User
Super User

Re: Count the Number of Selected Items in a List Box

Hi

 

Select the ListBox, and set Default as context variable, say

Default = lb

Meantime, set

OnHidden = UpdateContext{lb: " "}); UpdateCobtext({lb: ""}) (or set on any button, etc.)

 

Once you have selected the value in ListBox, and when you navigate away, it will be set to no selection and when you return to the same screen, you will no more selection.

 

The above UpdateContext can be used with any behaviour formula.

 

Hope this helps.

hpkeong
audrieg
Level 10

Re: Count the Number of Selected Items in a List Box

I tried that but it's not clearing the selection. Does it matter that it's a multi-select list box?

Super User
Super User

Re: Count the Number of Selected Items in a List Box

Hi

 


@audrieg wrote:

I tried that but it's not clearing the selection. Does it matter that it's a multi-select list box?


 

It doesn't matter.

UpdateContext({xx: " "}); UpdateContext({xx: ""})

take note of : 1st one: " " (with space in between), 2nd one: "" (no space in between)

 

FYI: This is used very commonly in PowerApps.

 

Hope you understand my poor explanation.

 

Screenshot (214).pngScreenshot (215).png

 

hpkeong

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 145 members 4,623 guests
Please welcome our newest community members: