cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kudo Kingpin
Kudo Kingpin

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
Highlighted
Community Support
Community Support

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.
Highlighted
Kudo Kingpin
Kudo Kingpin

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
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 (6,201)