cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Field Helper V
Helper V

Distinct and sum 2 columns

Hello, 

 

In my sharepoint list i have the following items:

 

Title - Number

 

Test A - 4

Test A - 2

Test A - 2

Test B - 3

Test C - 2

Test B - 3

 

I want to put that information in a gallery but remove duplicates and add them together, so in reality, the gallery on PowerApps should be showing this:

 

Test A - 8

Test B - 6

Test C - 2

 

I can remove duplicates, but not sum.

Using sum will give a random number that i do not want

 

Can somebody help?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Distinct and sum 2 columns

@Field 

This is a classic Collections problem called "How can I GROUPBY a column and SUM the values".  Here's the solution

 

ClearCollect(
    myGroupedCollection,
    GroupBy(your_datasource_name,"Title","GroupedItems")
);

ClearCollect(
    mySolution,
    DropColumns(
        AddColumns(myGroupedExpenses,"Sum of Value",Sum(GroupedItems,Value)),
        "GroupedItems"
    )
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

1 REPLY 1
Super User
Super User

Re: Distinct and sum 2 columns

@Field 

This is a classic Collections problem called "How can I GROUPBY a column and SUM the values".  Here's the solution

 

ClearCollect(
    myGroupedCollection,
    GroupBy(your_datasource_name,"Title","GroupedItems")
);

ClearCollect(
    mySolution,
    DropColumns(
        AddColumns(myGroupedExpenses,"Sum of Value",Sum(GroupedItems,Value)),
        "GroupedItems"
    )
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Power Platform 2020 release wave 1 plan

Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

Top Solution Authors
Top Kudoed Authors
Users online (7,386)