cancel
Showing results for
Did you mean:
Helper I

## Combine multiple columns to find distinct combinations

I'm trying to wrap my head around an issue. I have a table that contains two columns that together make up a unique set of activity.

Here is an example dataset:

{Project, Subproject, OriginalAmount, AmendedAmount}

{ProjectX, AWY18, \$0, \$700}

{ProjectX, AWY18, \$5000, \$0}

{ProjectX, AWY19, \$400, \$350}

{ProjectY, AWY18, \$500, \$0}

{ProjectY, AWY18, \$0, \$-80}

My goal is to eventually create a collection that summarizes by each Project and Subproject. The end result of the collection should look like this:

{ProjectX, AWY18, \$5700}

{ProjectX, AWY19, \$750}

{ProjectY, AWY18, \$420}

Doing the sum would be easy if I could create a table that was just the unique Project code and Subproject code. So I'm really trying to create a collection that would look like this:

{ProjectX, AWY18}

{ProjectX, AWY19}

{ProjectY, AWY18}

If I had that collection, I could just do:

ForAll(colProjects, Sum(

Sum(Filter(ProjectTable,Project=colProject.Project And SubProject=colProject.SubProject),OriginalAmount),

Sum(Filter(ProjectTable,Project=colProject.Project And SubProject=colProject.SubProject),AmendedAmount)

))

TL;DR

How do I find the unique values for the combination of two columns?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

Sorry. Typo in the formula.

Should be:

``````AddColumns
GroupBy(ProjectTable,
"Project", "Subproject", "_data"
),
"ProjectSum", Sum(_data, OriginalAmount) + Sum(_data, AmendedAmount)
)``````
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
3 REPLIES 3
Super User

You should be looking to the GroupBy function for what you need.

Ex:

``````AddColumns
GroupBy(ProjectTable,
"Project", "Subproject", "_data"
),
"ProjectSum", Sum(_data.OriginalAmount) + Sum(_data.AmendedAmount)
)``````

This would produce the table of results that you are looking for.

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Helper I

I'm getting an error on the Sum formulas saying it is expecting a number but receiving a table. This is annoying because the documentation clearly states that you can give Sum a table.

Super User

Sorry. Typo in the formula.

Should be:

``````AddColumns
GroupBy(ProjectTable,
"Project", "Subproject", "_data"
),
"ProjectSum", Sum(_data, OriginalAmount) + Sum(_data, AmendedAmount)
)``````
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Announcements

#### Celebrating the May Super User of the Month: Laurens Martens

@LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!

#### Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!