web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using a listbox, count...
Power Apps
Answered

Using a listbox, counting the number of selected rows and attribute count to a value

(0) ShareShare
ReportReport
Posted on by 99

Hi,

 

How can I count the number of select rows in a list box and attribute all those select items to one value i.e. 3.

The current row selection will tally all the number of select rows, meaning if I select 2 rows, the result is 2.

What I want to do is say whether you select one item or 5 items, the result is 3. It's a scoring system.

 

Selecting from the approved list, gets you 3, selecting from the non functional list, gives you a 1, selecting from

both lists give you a 2.

Gana_Dube_1-1668257008398.png

The code for counting the selected rows is as below.

 

 

CountRows(listbox1.SelectedItems)

 

 

 

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Gana_Dube 

    If(CountRows(listbox1.SelectedItems)>0,3,0) or

    If(CountRows(listbox1.SelectedItems)>0,3,Blank())

  • Gana_Dube Profile Picture
    99 on at

    @Drrickryp the result I'm getting from your code is a Boolean value, I think because of the Or condition. The result I am trying to get is something as below.

     

    If(
    	CountRows(listbox1.SelectedItems) > 0 , 3, 
    	If(And(CountRows(listbox1.SelectedItems) > 0, CountRows(listbox2.SelectedItems) > 0), 2,
    	CountRows(listbox2.SelectedItems) > 0 , 1, 0 ))

    The first and the last condition work, the middle condition does not work.

     

    Below does not work.

    If(And(CountRows(listbox1.SelectedItems) > 0, CountRows(listbox2.SelectedItems) > 0), 2,

    Meaning if any items of list1 and list2 are selected, the result should be 2.

     

     

     

    Thank you.

  • Verified answer
    AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    Hey @Gana_Dube 

     

    Have you tried the condition in this order:

    If(
    And(
    CountRows(listbox1.SelectedItems) > 0,
    CountRows(listbox2.SelectedItems) > 0)
    ,2,
    CountRows(listbox1.SelectedItems) > 0 
    ,3, 
    CountRows(listbox2.SelectedItems) > 0
    ,1,0)
  • Gana_Dube Profile Picture
    99 on at

    @AJ_Z this worked as requested🙂, I'm chuffed. Thank you very much.

  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    Hey Gana_Dube,

     

    I am delighted I could help and thanks Drrickryp for your work getting close to the solution :).

     

    Take care and good luck with your Power App!

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Gana_Dube 

    If I am understanding, you actually have 4 possible conditions as following

    With({cond1:CountRows(listbox1.SelectedItems) > 0 && CountRows(listbox2.SelectedItems) > 0, // both have selections
     cond2:CountRows(listbox1.SelectedItems) > 0 && CountRows(listbox2.SelectedItems) = 0, // only lb1 has selections
     cond3:CountRows(listbox1.SelectedItems) = 0 && CountRows(listbox2.SelectedItems) > 0, // only lb2 has selections
     cond4:CountRows(listbox1.SelectedItems) = 0 && CountRows(listbox2.SelectedItems) = 0 // neither has selections 
     },
     If(
     cond1, 2,
     cond2, 3, 
     cond3, 1,
     cond4, 0
     )
    ) 

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 136 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 109 Super User 2026 Season 2

Last 30 days Overall leaderboard