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 / CountRows not working ...
Power Apps
Answered

CountRows not working properly - how to re-write the code for same result

(0) ShareShare
ReportReport
Posted on by 2

I am developing app in teams power app. 

Data in the tables, having only 128 records

 

I wanted if the gallery filter count = 1 then false and

If no record then true

 

I have the below code on select event of the Gallery control.

Some time it works, some time it hangs, no result.

I click here there on the screen and then on the gallery filtered item again, then it works,

Could not understand, why it hangs for the result of true or false 

Does it need to write in another way to obtain the true false result

 

If(
 CountRows(
 Filter(
 TableMachRemarks,
 Model = SearchResultGallery_4.Selected.Model && SerialNo = SearchResultGallery_4.Selected.Serial
 )
 ) = 1,
 Set(
 gblRemarksNewRecord,
 false
 ),

 CountRows(
 Filter(
 TableMachRemarks,
 Model = SearchResultGallery_4.Selected.Model && SerialNo = SearchResultGallery_4.Selected.Serial
 )
 ) = 0,
 Set(
 gblRemarksNewRecord,
 true
 )
)

 

Categories:
I have the same question (0)
  • IAmIntractable Profile Picture
    280 on at

    If(

        CountRows(

            Filter(

                TableMachRemarks,

                Model = SearchResultGallery_4.Selected.Model && SerialNo = SearchResultGallery_4.Selected.Serial

            )

        ) = 1,

        Set(

            gblRemarksNewRecord,

            false

        ),

        Set(

            gblRemarksNewRecord,

            true

        )

    )

  • MIA27 Profile Picture
    2 on at

    I tried the code which you mentioned, the result was same, then added that getting 0 coding part.

     

    Any other idea to get this done

     

  • Verified answer
    WarrenBelz Profile Picture
    154,994 Most Valuable Professional on at

    @MIA27 ,

    Try

    Set(
     gblRemarksNewRecord,
     IsBlank(
     LookUp(
     TableMachRemarks,
     Model = SearchResultGallery_4.Selected.Model && 
     SerialNo = SearchResultGallery_4.Selected.Serial
     ).Model
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • MIA27 Profile Picture
    2 on at

    Dear Mr. Warren,

    Thank you. Applied the code, it worked.

     

     

    As the code is applied on select event of Gallery, One thing I noticed that when it is false, the screen textbox value based on true or false get updated immediately.

    But when it is true, it need to click on the gallery manually - to run the Onselect  event.

     

    Is it possible we can improve the code, so that in both situation it get in action without manually clicking on the gallery item. For example something default of gallery can be done .

     

    Please guide if possible, as true action is not getting into action

     

    regards

     

     

  • Verified answer
    WarrenBelz Profile Picture
    154,994 Most Valuable Professional on at

    @MIA27 ,

    Your search criteria contains SearchResultGallery_4.Selected, so you need to select a record to gain access to the relevant fields in it. You could look at making the Gallery Default reflect the record you want selected, so whatever your Gallery Items is, wrap it in First() and put this on the Default.

    First(
     YourGalleryItemsHere
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • MIA27 Profile Picture
    2 on at

    As the code is running on the gallery SearchResultGallery_4 on which on select event code is been applied to obtain True or false, 

    you mean in the same gallery SearchResultGallery_4 - , on its default property i need to put the code like below :

    Just confused, please clarify :

     

    First (
    Set(
     gblRemarksNewRecord,
     IsBlank(
     LookUp(
     TableMachRemarks,
     Model = SearchResultGallery_4.Selected.Model && 
     SerialNo = SearchResultGallery_4.Selected.Serial
     ).Model
     )
    )
    )

     

     

  • Verified answer
    WarrenBelz Profile Picture
    154,994 Most Valuable Professional on at

    @MIA27 ,

    I meant the Items of the Gallery - that appears to be the OnSelect

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 476

#2
WarrenBelz Profile Picture

WarrenBelz 365 Most Valuable Professional

#3
Vish WR Profile Picture

Vish WR 339

Last 30 days Overall leaderboard