cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

CountIf and Variables

Hey guys! I am trying to count how many records there are based on a certain condition, but it seems like it is not working too well. 

 

"Current Month Count for " & User & ": " & CountIf(Collection1 , IsMatch('Created By'.DisplayName, "Hong, Chhun", Contains))

 

This one works indefinitely since the string matches the exact string in the SharePoint list. But this only works for me, I need it to work for everyone who logs on. So I tried:

 

Set(User, User().FullName)- On start 

"Current Month Count for " & User & ": " & CountIf(Collection1 , IsMatch('Created By'.DisplayName, User , Contains))

 

And it keeps saying that there is something wrong with the format. Please Help! 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Continued Contributor
Continued Contributor

Re: CountIf and Variables

No worries.  We all start somewhere.  The question per PowerApps is the same w/ any environment: just because you can do a thing, should you do a thing?  Smiley LOL

Anyway, IsMatch should do what you want here.  I'd still consider doing:

  • User().EmailAddress
  • Collection1.'Created By'.Email

More accurate, less resources and faster search.  That might even be your issue.  Sometimes the "User().DisplayName" is different from the one in SharePoint (particularly if you're in a hybrid environment).  However, the Email is always correct.

Finally, if you don't want to switch fields, then at least do a Lower or Upper function on your string to ensure matches.  Case could also be the problem in addition to formatting (e.g. First Last vs. Last, First, etc.)

 

View solution in original post

5 REPLIES 5
Highlighted
Continued Contributor
Continued Contributor

Re: CountIf and Variables

Just a quick non-sequitor comment here (because I've seen several posts around this recently).  Using "name" as an identifier is not great.  Email is essentially a unique identifier and is less likely to have formatting issues across platforms.  

Anyway, the IsMatch() function returns a boolean (e.g. True/False).  Is that really what you're after here?

For example: "Current Month Count for " & User & ": " & CountIf(Collection1 , IsMatch('Created By'.DisplayName, "Hong, Chhun", Contains))

Becomes: "Current Month Count for " & User & ": " & CountIf(Collection1 , True)

Highlighted
Anonymous
Not applicable

Re: CountIf and Variables

Noted, thank you for the tip! Just started PowerApps last week! Lol

 

But basically, what I am trying to do is to count the number of records that the user has inputted for this month. I am utilizing the sharepoint 'created by' column to look for how many each person has entered for the month. Here is an updated one I just figured out. 

 

"Current Month Count for " & User & ": " & CountRows( Filter(
Collection1,
Created >= Date(Year(Today()), Month(Today()), 1),
Created < Date(Year(Today()), 1 + Month(Today()), 1), IsMatch('Created By'.DisplayName, "Hong, Chhun")))

 

Still having issues with the isMatch part (Bolded) when comparing to the column 'Created By'. Should I be using a different function other than isMatch?

 

Highlighted
Continued Contributor
Continued Contributor

Re: CountIf and Variables

No worries.  We all start somewhere.  The question per PowerApps is the same w/ any environment: just because you can do a thing, should you do a thing?  Smiley LOL

Anyway, IsMatch should do what you want here.  I'd still consider doing:

  • User().EmailAddress
  • Collection1.'Created By'.Email

More accurate, less resources and faster search.  That might even be your issue.  Sometimes the "User().DisplayName" is different from the one in SharePoint (particularly if you're in a hybrid environment).  However, the Email is always correct.

Finally, if you don't want to switch fields, then at least do a Lower or Upper function on your string to ensure matches.  Case could also be the problem in addition to formatting (e.g. First Last vs. Last, First, etc.)

 

View solution in original post

Highlighted
Anonymous
Not applicable

Re: CountIf and Variables

Wow, works like a charm! Thank you so much!!!! I don't even need to set the User variable initially onstart! and its User().Email

 

Hahahaha, Thank you!

Highlighted
Continued Contributor
Continued Contributor

Re: CountIf and Variables

Glad it worked.  But also not surprising that I fat-fingered at least one thing in my reply.  Smiley LOL

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (9,822)