cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gasilva8
Helper II
Helper II

Error using CountRows of a list

I'm trying to check if a value (which comes from a Variable) exists in a SP List.

I tried this, and returned true (I don't know if I used the correct syntax, but it worked!):

 

If(!IsBlank(LookUp('SPList', Variable = Column,"*"&Variable&"*"))

 

Now I'm trying to count rows if contains the Variable, but returns 0:

 

CountRows(Filter('SPList', Column = "*"&Variable&"*"))

 

How can I workaround that?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@gasilva8 

For the first formula, you can use the following a little more easily:

If(!LookUp('SPList', Variable = Column,"*" & Variable & "*", true), ... )

In this case, LookUp will return true if the record exists.

 

Since CountRows is not delegable, it seems to sometimes ignore itself.

Try the following for your second formula:

With({_data: Filter('SPList', Column = "*" & Variable & "*")}
    CountRows(_data)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
C-Papa
Super User
Super User

Hi, what you have should work, are you trying to use wild cards though? e.g. "*"? does you data actual contain * e.g. "*MyValue*"

 

the below works for me but this will return a number so you would need to put it in a text property to view it

CountRows(Filter('SPList', Column = Variable))

RandyHayes
Super User
Super User

@gasilva8 

For the first formula, you can use the following a little more easily:

If(!LookUp('SPList', Variable = Column,"*" & Variable & "*", true), ... )

In this case, LookUp will return true if the record exists.

 

Since CountRows is not delegable, it seems to sometimes ignore itself.

Try the following for your second formula:

With({_data: Filter('SPList', Column = "*" & Variable & "*")}
    CountRows(_data)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Just to add to @RandyHayes, i think you missed a comma,

 

With({_data: Filter('SPList', Column = "*" & Variable & "*")},
CountRows(_data)
)

RandyHayes
Super User
Super User

@C-Papa 

Yes, thank you...missed a comma.  Not unusual when typing in formulas freehand.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,734)