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

Calculate the average of a comma separated valuelist

I'm using this formula for a label

LookUp(prchk, Project_ID.Value = ThisItem.ID,'User ratings')

and it shows as a comma separated list in the label, e.g. 4,5,4,5,
using

LookUp(prchk, Project_ID.Value = ThisItem.ID, Left('User ratings', Len('User ratings')-1))

I can get rid of the trailing comma, so I assume 'User ratings' is a string indeed

However

Average(LookUp(prchk, Project_ID.Value = ThisItem.ID, Left('User ratings', Len('User ratings')-1)))

returns nothing, and

Split(LookUp(prchk, Project_ID.Value = ThisItem.ID, Left('User ratings', Len('User ratings')-1)),",")

results in an "Expected Text Value" error.


I understand this column type is not supported (for updating SP list from PowerApps), but if the returned value is a comma separated value string I can manipulate with Len(), shouldn't there be a way to calculate the average from that string, or splitting it into a table and then calculate the average on the value column?
I tried as well

Text(LookUp(prchk, Project_ID.Value = ThisItem.ID, Left('User ratings', Len('User ratings')-1)),Number)

Which works with both, textformat Text or Number, but still I can't neither average nor split it. Help would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
mike528
Level: Powered On

Re: Calculate the average of a comma separated valuelist

@Beat 

 

I started with your comma delimited list in varList.

UpdateContext({varList:"4,5,6,7"})

 

Then split it into a collection 

ClearCollect(colList,Split(varList,","))


Then take the average of the collection, the default column name of the single column collection is Result
UpdateContext({Average:Average(colList,Result)})

 

as a single expression you can use 

UpdateContext({Average:Average(Split(varList,","),Result)})

 

 

Hope this help!

Mike

View solution in original post

2 REPLIES 2
mike528
Level: Powered On

Re: Calculate the average of a comma separated valuelist

@Beat 

 

I started with your comma delimited list in varList.

UpdateContext({varList:"4,5,6,7"})

 

Then split it into a collection 

ClearCollect(colList,Split(varList,","))


Then take the average of the collection, the default column name of the single column collection is Result
UpdateContext({Average:Average(colList,Result)})

 

as a single expression you can use 

UpdateContext({Average:Average(Split(varList,","),Result)})

 

 

Hope this help!

Mike

View solution in original post

Beat
Level 8

Re: Calculate the average of a comma separated valuelist

@mike528I had no chance to actually try it until today. Happy new year 🙂
It does work, many thanks. I can use this on a form. Is this as well possible in a gallery, for each item? How would I go about that?

Helpful resources

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

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

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 (4,598)