cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PhilD
Level 8

Count occurrences and filter by this number

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-colu...

 

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

2 REPLIES 2
Community Support Team
Community Support Team

Re: Count occurrences and filter by this number

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

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PhilD
Level 8

Re: Count occurrences and filter by this number

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!

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (5,049)