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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Count occurrences and ...
Power Apps
Unanswered

Count occurrences and filter by this number

(0) ShareShare
ReportReport
Posted on by 1,011

I have a SharePoint list of items with a column 'Employee' that indicates the employee associated with the item. It is easy to get a gallery item label to show how many entries each user has like this (although possibly ineffficient)...

 

 

CountIf(Letters, 
EmployeeName.Email = ThisItem.EmployeeName.Email,
EventDate >= (Today()-SliderLookBackDays.Value)
)

I would like to filter this gallery to show only those items that have more than X number of occurrences but doing so produces the circular reference warning. I tried to use a collection with AddColumn but couldn't figure out how to iterate the list in the same way as the 'ThisItem' allows in a gallery so my Occurrence column always showed the total for the whole gallery instead of the total for that employee. Not sure if this is even the right way to go about it...

 

What would be the correct pattern to use to calculate the number of occurrences for each employee in a list, and then provision a view filtered to show only those above a certain number of occurrences? The list is relatively small with only a few hundred entries for an entire year.

 

This is what I tried in a collection but this obviously makes no sense around the "EmployeeName.Email = EmployeeName.Email" part. The code below creates the source, with an extra column "Occurrences" that has 328 in every row (the number of items in the list).

 

 

ClearCollect(colLetters, 
	AddColumns('Letters',
		"Occurrences", CountIf(Letters, EmployeeName.Email = EmployeeName.Email, EventDate >= (Today()-SliderLookBackDays.Value))
	)
)

 I feel like this is the right direction but I'm kind of lost as to how to construct the statement. 

 

UPDATE:

Looking at this...may solve the problem.

https://powerusers.microsoft.com/t5/General-Discussion/Count-the-times-a-value-Appears-within-a-column-into-a/td-p/55162

 

UPDATE 2 

OKay... I give up. There seems to be no way to reference the complex person field, in my case 'EmployeeName.DisplayName' Only plain text fields work.  Smiley Sad

Categories:
I have the same question (0)
  • v-micsh-msft Profile Picture
    on at

    Take a try with the formula below:

    ClearCollect(colLetters, 
    	 AddColumns('Letters',
    		 "Occurrences", 
    LookUp(
    AddColumns(
    Distinct('Letters',EmployeeName.Email), "Occurrences1", CountIf(Letters,
    EmployeeName.Email=Result,
    EventDate >= (Today()-SliderLookBackDays.Value)
    )
    ),
    Result=EmployeeName.Email,Occurrences1) ) )

    Regards,

    Michael

     

  • PhilD Profile Picture
    1,011 on at

    Thanks @v-micsh-msft

     

    I used your formula to build the collection which worked to calculate the occurrences properly (I have since changed the "lookback" control to a dropdown) without any issue.

     

    ClearCollect(colLetters, 
    	 AddColumns('Letters',
    		 "Occurrences", 
     LookUp(
     AddColumns(
     Distinct('Letters',EmployeeName.Email),
     "Occurrences1",
     CountIf(Letters,
     EmployeeName.Email=Result,
     EventDate >= (Today()-DropdownLookBackPeriod.Selected.NumericValue)
     )
     ),
     Result=EmployeeName.Email,Occurrences1)
    	 )
     )

     

    On the display gallery, I used this to try and filter by the number of occurrences and still got the circular reference error. 

     

    Filter(colLetters, Value(LabelOccurencesInLookbackPeriod.Text) >= SliderOccurences_1.Value)

    Would this be inherently easier if the data source was a SQL Server database (I think the answer is likely yes)?

     

    Thanks again for the direction!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard