cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Power Automate
Power Automate

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
Highlighted
Power Apps
Power Apps

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

You can use the CountRows function to get that number:

 

CountRows(ListBox1.SelectedItems)

View solution in original post

8 REPLIES 8
Highlighted
Community Champion
Community Champion

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
Highlighted
Power Automate
Power Automate

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)

Highlighted
Power Apps
Power Apps

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

You can use the CountRows function to get that number:

 

CountRows(ListBox1.SelectedItems)

View solution in original post

Highlighted
Power Automate
Power Automate

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!!

Highlighted
Community Champion
Community Champion

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
Highlighted
Community Champion
Community Champion

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
Highlighted
Power Automate
Power Automate

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?

Highlighted
Community Champion
Community Champion

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
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,961)