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

Creating a new summarized collection based on a query

Hello, all.

 

I'm pulling data from my SQL Server in this format:

OriginalSales.PNG

 

I'd like to create another Collection grouped by DEPARTMENT and would summarize the Sales, like the image below:

 

Sales Sumarized.PNG

 

Does anyone may help me?

 

thanks,

Paulo.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Creating a new summarized collection based on a query

You can use the GroupBy function to do that - there are some examples in the documentation page that show exactly how to do that. In your case, you're probably looking at something like the expression below:

AddColumns(
    GroupBy('[dbo].[YourTableName]', "Department", "ByDepartment"),
    "Sales",
    Sum(ByDepartment, Sales))

View solution in original post

4 REPLIES 4
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Creating a new summarized collection based on a query

You can use the GroupBy function to do that - there are some examples in the documentation page that show exactly how to do that. In your case, you're probably looking at something like the expression below:

AddColumns(
    GroupBy('[dbo].[YourTableName]', "Department", "ByDepartment"),
    "Sales",
    Sum(ByDepartment, Sales))

View solution in original post

Super User
Super User

Re: Creating a new summarized collection based on a query

Hi !

You can use a combncombin of GroupBy(), AddColumns() and DropColumns() functions :

 

ClearCollect(
SalesByDepartment,

GroupBy( OriginalCollection, "Department", "MonthSales" ) ) ClearCollect( DepartmentSalesSum, AddColumns( SalesByDepartment "Sum of departments sales", Sum(MonthSales, Sales ) ) ) ClearCollect( DepartmentSalesSumOnly, DropColumns( DepartmentSalesSum, "MonthSales" ) )

 First, Group your initial table By department.

Second, Add a Column with the sum of all sales.

Last, drop the unneeded columns (the array of month/sales by department).

 

It is pretty well explained on the Agregate results example part of the GroupBy documentation.

 

Theo

plzampieri
Level: Powered On

Re: Creating a new summarized collection based on a query

Thank you so much, Carlos. 

I created a new Collection and inside of if, I created the column you've mentioned. 

It worked.

 

Highlighted
plzampieri
Level: Powered On

Re: Creating a new summarized collection based on a query

Thank you.

It's working now and thanks for giving me more examples.

Have a great day.

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 (9,740)