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

GroupBy and Sum

Hi,

 

I have values in Title 3(10000, 20000,30000,10000...) and some values in subtitle 2. How can I perform group by title 3 and then have summarized values from subtitle 2?

 

PowerApps3.png

 

For example:

10 000: 88862,38

20 000: 93093,92

30 000: 156567,04

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: GroupBy and Sum

Assuming that the data source name is called 'MyDataSource', the value in Title3 comes from a column called 'TitleValue', and the value in Subtitle2 comes from a column called 'SubtitleValue', then you first need to group the data source by the title:

GroupBy(MyDataSource, "TitleValue", "ByTitleValue")

Then you can sum the value of all groups by "adding" a new column to the data source:

AddColumns(
    GroupBy(MyDataSource, "TitleValue", "ByTitleValue"),
    "SumOfSubtitleValue",
    Sum(ByTitleValue, SubtitleValue))

This last expression gives you a table with a columns for the TitleValue (10000, 20000, 30000, ...) and a column for the sum of the SubtitleValue, which you can then display in a gallery / table.

5 REPLIES 5
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: GroupBy and Sum

Assuming that the data source name is called 'MyDataSource', the value in Title3 comes from a column called 'TitleValue', and the value in Subtitle2 comes from a column called 'SubtitleValue', then you first need to group the data source by the title:

GroupBy(MyDataSource, "TitleValue", "ByTitleValue")

Then you can sum the value of all groups by "adding" a new column to the data source:

AddColumns(
    GroupBy(MyDataSource, "TitleValue", "ByTitleValue"),
    "SumOfSubtitleValue",
    Sum(ByTitleValue, SubtitleValue))

This last expression gives you a table with a columns for the TitleValue (10000, 20000, 30000, ...) and a column for the sum of the SubtitleValue, which you can then display in a gallery / table.

RenatoF
Level: Powered On

Re: GroupBy and Sum

Wow, thank you. I didn't know for this addcolumns. This helps me a lot Smiley Happy 

KubraDemir
Level: Powered On

Re: GroupBy and Sum

Hi everyone,

 

I found a new method for summation of two or many different data, via GroupBy and Sum functions.
Gallery item's code:
GroupBy("database";  "item1";"item2"; "item3"; "GroupName")

Code for summation all textbox by the GroupName:
TextBox's default code:
Sum("GroupName"; "Wil summation column name")

TonyPower
Level: Power Up

Re: GroupBy and Sum

that worked!!

PytByt
Level: Powered On

Re: GroupBy and Sum

Hi Mr. @CarlosFigueira 

can you show me with SS or a short video? even a gif could be accepted too for me the noob... hehe,

 

thanks.


@CarlosFigueira wrote:

Assuming that the data source name is called 'MyDataSource', the value in Title3 comes from a column called 'TitleValue', and the value in Subtitle2 comes from a column called 'SubtitleValue', then you first need to group the data source by the title:

GroupBy(MyDataSource, "TitleValue", "ByTitleValue")

Then you can sum the value of all groups by "adding" a new column to the data source:

AddColumns(
    GroupBy(MyDataSource, "TitleValue", "ByTitleValue"),
    "SumOfSubtitleValue",
    Sum(ByTitleValue, SubtitleValue))

This last expression gives you a table with a columns for the TitleValue (10000, 20000, 30000, ...) and a column for the sum of the SubtitleValue, which you can then display in a gallery / table.


 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 225 members 4,802 guests
Please welcome our newest community members: