cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mssss
Level: Powered On

Sum in PowerApps useing ClearCollect

Hello, here I have a question.

I would like to create a collection table “salesecollect” form table “sales”.

 

Data base CDS

Entity type custom

 

sales

productscode

qty

aaa

1

aaa

5

bbb

5

bbb

5

 

Created collection table: salesecollect

productscode

salesqty

aaa

6

bbb

10

 

ClearCollect(salescollect,

 AddColumns(Distinct(sales, productscode), "salesqty", Sum(sales, salesqty)));

 

All sumquy shows “16” on my table.

 

please help me...

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Sum in PowerApps useing ClearCollect

To recreate your scenario, I created a collection: 

ClearCollect(SalesCollection, {productcode: "AAA", qty: 1}, {productcode: "BBB", qty: 5}, {productcode: "AAA", qty: 5}, {productcode: "BBB", qty: 5})

 

The collection looks like this:

Sales1.PNG

 

Now, on a button's OnSelect property, I have the following formula: 

 

ClearCollect(FinalResult1, DropColumns(AddColumns(GroupBy(SalesCollection, "productcode", "qty"), "Qty", Sum( qty, qty)),"qty"))

 

Using this, my collection FinalResult1 looks like this (Qty is the name I gave to the new column): 

 

Sales2.PNG

 

Let me know if this doesnt work for you. 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

View solution in original post

8 REPLIES 8
Super User
Super User

Re: Sum in PowerApps useing ClearCollect

To recreate your scenario, I created a collection: 

ClearCollect(SalesCollection, {productcode: "AAA", qty: 1}, {productcode: "BBB", qty: 5}, {productcode: "AAA", qty: 5}, {productcode: "BBB", qty: 5})

 

The collection looks like this:

Sales1.PNG

 

Now, on a button's OnSelect property, I have the following formula: 

 

ClearCollect(FinalResult1, DropColumns(AddColumns(GroupBy(SalesCollection, "productcode", "qty"), "Qty", Sum( qty, qty)),"qty"))

 

Using this, my collection FinalResult1 looks like this (Qty is the name I gave to the new column): 

 

Sales2.PNG

 

Let me know if this doesnt work for you. 

 

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

View solution in original post

mssss
Level: Powered On

Re: Sum in PowerApps useing ClearCollect

thank you!

Worked well!

 

Is it possible vlookup sum QTY to productlist like this?

table: productlist

 

productcode

AAA

BBB

CCC

DDD

Super User
Super User

Re: Sum in PowerApps useing ClearCollect

You mean you want to lookup Qty based on product code? If you are asking a user to enter the product code in a text input box or from a dropdown, then you can use something like this:

Lookup(FinalResult1, productcode = label1.text).Qty

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

Hardit(Haman)

ClearCollect(FinalResult1, DropColumns(AddColumns(GroupBy(SalesCollection, "productcode", "qty"), "Qty", Sum( qty, qty)),"qty"))



Using this, my collection FinalResult1 looks like this (Qty is the name I gave to the new column):
mssss
Level: Powered On

Re: Sum in PowerApps useing ClearCollect

Thank you for your help!


I would like to Created collection table by using  “productlist”
table and  “sales”table.

not imaging entering codes.

 

Created collection table: salesecollect

procudtscode

salsesQTY

aaa

6

bbb

10

ccc

0

ddd

0

 

Thank you!

Community Support Team
Community Support Team

Re: Sum in PowerApps useing ClearCollect

Hi @mssss ,

Could you please share a bit more about your scenario?

Do you want to intergrate the sales table with your productlist table, and then sum QTY value for each productcode (e.g. AAA, BBB, CCC, DDD)?

 

Please consider add a Data Table control in your app, set the Items property to following:

RemoveColumns(
     AddColumns(
           GroupBy(
                  productlist,
                  "productcode",
                  "GroupData"
           ),
           "QTY",
           Sum(Filter(sales, productscode = productcode), qty)
     ),
     "GroupData"
)

then enable productcode column, and QTY column within the Data Table, then the records would be shown up.

You could also consider save above formula result into a collection, then use that collection as data source in your app.

 

Please also consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: Sum in PowerApps useing ClearCollect

Hi @msss if my response solved your original question, please accept it as a solution so someone who is facing a similar problem can find the answer to it.

Thanks
Hardit (Haman)
mssss
Level: Powered On

Re: Sum in PowerApps useing ClearCollect

Hi, v-xida-msft

 

thank you to for your help!
worked !

mssss
Level: Powered On

Re: Sum in PowerApps useing ClearCollect

Thank you for you help!!

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 (8,151)