cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MarkSL
Frequent Visitor

Populate a gallery with summarised data from a collection?

Hi,

 

I have a SQL view which summarises orders by Year and Month and giving a count of orders, eg:

 

Jan 2019 | 350 Orders
Feb 2019 | 260 Orders
Mar 2019 | 400 Orders

I have a gallery,  galleryOrderSummary which uses this sumarised view as its datasource and then a 2nd gallary, galleryOrderDetail, which is filtered based on galleryOrderSummary..  This all works well, so when I select Feb 2019 from galleryOrderSummary, 20 rows are shown in galleryOrderDetail.

 

 

However, I would like to offer the users some filters, such as Sales Person and Product, which will filter what is reported in galleryOrderSummary and thereby galleryOrderDetail.

 

I can change my SQL view to include these new summary levels, so the summarised data would like the following:

 

Jan 2019 | Andrew | 150 Orders etc
Jan 2019 | Bob | 100 Orders etc 
Jan 2019 | Charlie |50 Orders etc
Feb 2019 | Andrew |20 Orders etc
...
..

However I want to keep galleryOrderSummary  showing one row per Year / Month as before. 

 

If my filter for Sales Person is not populated, then Jan 2019 will show 350 orders, yet if the user has filtered on Sales Person = Andrew, then the colunt of orders will be 150 in Jan.

 

Is there a way to set my galleryOrderSummary to be summarised, so that it only ever shows one row Year per Month, even though there may be multiple rows per Year and Month?

 

Many thanks and hope the above is understandable!

 

Mark

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@MarkSL 

I believe, based on your description, that you are attempting to return multiple rows of data for a month and year, yet you want to have only one row for the month and the year displayed in your Summary gallery that would represent the total of all the sales persons (other rows).

Something like this:

MarkSL.png

By the way...I used your data in this, but you had a math error in your original post - you mentioned that Jan 2019 would have 350 orders, yet your sample data, when summed, only came to 300.

 

The key to this would be to use the GroupBy function to group your data by Year and Month first of all, but, if a selection of a sales person is made, then you would be Grouping the data by the *filtered* list of data.

Something like this:

GroupBy(
       Filter(yourViewData, 
          If(ddSalesPerson.Selected.Result= "", true, SalesPerson=ddSalesPerson.Selected.Result) 
), "Year", "Month", "Orders")

This will filter the view data by the selected sales person - if selected.  And then it will group it by year and month and the create a column called Orders with a table of the records that match that Year and Month.  This can then be used later to sum the totals in your gallery (Sum(ThisItem.Orders, Orders))

 

To better explain and demonstrate this, I have attached a sample app that uses your data and provides what I believe to be your original requirement.  Added bonus, I put in logic to narrow down not only by sales person, but also by month.

Take a look over it and see if it 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!

View solution in original post

6 REPLIES 6
wyotim
Resident Rockstar
Resident Rockstar

Hey @MarkSL, to do what you are wanting you could add some conditional filtering to galleryOrderSummary by using an If function.

 

Let's say that your date field is named Date, your saleperson field is named Person, and your order total field is named Orders, and you have a combo box named ComboBox1 that has a list of the salespeople to filter by. Let's also assume that your gallery is a distinct list of the dates (which would keep the single month/year row component). If you add a text label with the following it will give totals by a selected individual if one is selected in the combo box and by all if the combo box doesn't have a selection:

If(
    ComboBox1.Selected.Result = Blank(),
    Sum(
colTestTable,
Orders
), Sum(
Filter(
colTestTable,
Person = ComboBox1.Selected.Result
),
Orders
)
)

You could apply similar logic to add multiple filter criteria, as well as adding this type of logic to the second gallery to achieve the same result. You could alternatively use Set to assign the ComboBox1.Selected.Result to a global variable if you need to use it for other things. The filter would then need the variable name instead of ComboBox1.Selected.Result.

 

Feel free to let me know if that helps or if I can assist with expanding your filter statement.

RandyHayes
Super User
Super User

@MarkSL 

I believe, based on your description, that you are attempting to return multiple rows of data for a month and year, yet you want to have only one row for the month and the year displayed in your Summary gallery that would represent the total of all the sales persons (other rows).

Something like this:

MarkSL.png

By the way...I used your data in this, but you had a math error in your original post - you mentioned that Jan 2019 would have 350 orders, yet your sample data, when summed, only came to 300.

 

The key to this would be to use the GroupBy function to group your data by Year and Month first of all, but, if a selection of a sales person is made, then you would be Grouping the data by the *filtered* list of data.

Something like this:

GroupBy(
       Filter(yourViewData, 
          If(ddSalesPerson.Selected.Result= "", true, SalesPerson=ddSalesPerson.Selected.Result) 
), "Year", "Month", "Orders")

This will filter the view data by the selected sales person - if selected.  And then it will group it by year and month and the create a column called Orders with a table of the records that match that Year and Month.  This can then be used later to sum the totals in your gallery (Sum(ThisItem.Orders, Orders))

 

To better explain and demonstrate this, I have attached a sample app that uses your data and provides what I believe to be your original requirement.  Added bonus, I put in logic to narrow down not only by sales person, but also by month.

Take a look over it and see if it 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!
v-yuxima-msft
Community Support
Community Support

Hi @MarkSL 

 

Do you test with @wyotim 's and @RandyHayes 's suggetstions,

If it works ,please accept it as solution.

 

Best Regards.

Yumia

Hi both, 

Thank you both for your help here Smiley Happy

@RandyHayes thank you so much for providing that example based on my sample data!  I am new to PowerApps and that it exactly the functionality I was trying to describe and then some!  So helpful to see your code and to pick up on how to do other things which I had been meaning to ask - like how to add a default entry to the top of my drop down boxes and a total box.

I am going to try and implement the GroupBy logic now, so may be back with further questions!

Cheers

Mark

 

MarkSL
Frequent Visitor

Hi @RandyHayes 

Got a question already if you don't mind!

I want to offer a 2nd Gallery, GalOrderDetail, which will filter my main datasource (the one which the summarised view is based upon), passing the Year and Month from GalOrderList, but with the addition of passing the Sales Person (which isn't a field in GalOrderList and only if a value is selected).
I have applied this logic to your example as GalOrderDetail.Items :

Filter(MarkSL, 
Month = galOrderList.Selected.Month,
If(ddSalesPerson.Selected.Result= blankSPSelector, true, SP=ddSalesPerson.Selected.Result)
)

Whilst this appears to work fine in your example where the source is a collection, it fires a delegation warning in my real world SQL instance and I do not get all the results.  Is there a way I can pre-determine if ddSalesPerson has a value and is not blankSPSelector?

I have tried putting the IF statement at the top and essentially coding two FILTERS, based on the state of ddSalesPerson, however I can't seem to get this to work and I am bothered that as I add another drop down it will just become a mess of nested IFs!

If(ddSalesPerson.Selected.Result= blankSPSelector, 
  Filter(MarkSL, 
  Month = galOrderList.Selected.Month,
  SP=ddSalesPerson.Selected.Result)
,
   Filter(MarkSL, 
   Month = galOrderList.Selected.Month)
)

Thoughts gratefully appreciated!

Mark

@MarkSL 

The formula you have for GalOrderDetail.Items is correct.

The fact that you are getting a delegation warning is normal.  The question I first have is, how big is your datasource?  If we are dealing with more rows than your app is set to return (found in your App Settings Advanced Settings section - the default is 500), then you will get poor/inaccurate/incomplete results.

 

Now, let's make sure we are working with the same information and are on the same page.

First - What specifically are you getting the delegation warning on? Which part of the formula?

Second - I noticed you had SP as the field name in the Filter formula - is this the name of your SalesPerson field, and what type of field is it?  That was just a sample name I had used in the demo app.

 

And...more importantly - you have already gone to the data source once to fill in your Order summary - do you really need to make another call to the datasource?

Have you considered setting your GalOrderDetails Items property to : GalOrderList.Selected.Orders ?  If I understand your view...you already have all the information you need in the Order column of the GroupBy that we did to populate the summary list. 

If that View you use to provide that information for the Summary does not include the order detail, then you will need to make another "trip" to the datasource to get it in your Order detail gallery (as you have been trying).  I would recommend a view for that as well.  In general, anything you can do on the data side to limit delegation issues, the better.  You will be limited to a maximum of 5000 rows to return or to perform a non-delegable function on.  

So...let's fill in some of the information from above and take it from there.

 

 

 

_____________________________________________________________________________________
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!

Helpful resources

Announcements

Exclusive LIVE Community Event: Power Apps Copilot Coffee Chat with Copilot Studio Product Team

  It's time for the SECOND Power Apps Copilot Coffee Chat featuring the Copilot Studio product team, which will be held LIVE on April 3, 2024 at 9:30 AM Pacific Daylight Time (PDT).     This is an incredible opportunity to connect with members of the Copilot Studio product team and ask them anything about Copilot Studio. We'll share our special guests with you shortly--but we want to encourage to mark your calendars now because you will not want to miss the conversation.   This live event will give you the unique opportunity to learn more about Copilot Studio plans, where we’ll focus, and get insight into upcoming features. We’re looking forward to hearing from the community, so bring your questions!   TO GET ACCESS TO THIS EXCLUSIVE AMA: Kudo this post to reserve your spot! Reserve your spot now by kudoing this post.  Reservations will be prioritized on when your kudo for the post comes through, so don't wait! Click that "kudo button" today.   Invitations will be sent on April 2nd.Users posting Kudos after April 2nd. at 9AM PDT may not receive an invitation but will be able to view the session online after conclusion of the event. Give your "kudo" today and mark your calendars for April 3rd, 2024 at 9:30 AM PDT and join us for an engaging and informative session!

Tuesday Tip: Unlocking Community Achievements and Earning Badges

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!     THIS WEEK'S TIP: Unlocking Achievements and Earning BadgesAcross the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. These badges each signify a different achievement--and all of those achievements are available to any Community member! If you're a seasoned pro or just getting started, you too can earn badges for the great work you do. Check out some details on Community badges below--and find out more in the detailed link at the end of the article!       A Diverse Range of Badges to Collect The badges you can earn in the Community cover a wide array of activities, including: Kudos Received: Acknowledges the number of times a user’s post has been appreciated with a “Kudo.”Kudos Given: Highlights the user’s generosity in recognizing others’ contributions.Topics Created: Tracks the number of discussions initiated by a user.Solutions Provided: Celebrates the instances where a user’s response is marked as the correct solution.Reply: Counts the number of times a user has engaged with community discussions.Blog Contributor: Honors those who contribute valuable content and are invited to write for the community blog.       A Community Evolving Together Badges are not only a great way to recognize outstanding contributions of our amazing Community members--they are also a way to continue fostering a collaborative and supportive environment. As you continue to share your knowledge and assist each other these badges serve as a visual representation of your valuable contributions.   Find out more about badges in these Community Support pages in each Community: All About Community Badges - Power Apps CommunityAll About Community Badges - Power Automate CommunityAll About Community Badges - Copilot Studio CommunityAll About Community Badges - Power Pages Community

Tuesday Tips: Powering Up Your Community Profile

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week's Tip: Power Up Your Profile!  🚀 It's where every Community member gets their start, and it's essential that you keep it updated! Your Community User Profile is how you're able to get messages, post solutions, ask questions--and as you rank up, it's where your badges will appear and how you'll be known when you start blogging in the Community Blog. Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile.     Password Puzzles? No Problem! Find out how to sync your Azure AD password with your community account, ensuring a seamless sign-in. No separate passwords to remember! Job Jumps & Email Swaps Changed jobs? Got a new email? Fear not! You'll find out how to link your shiny new email to your existing community account, keeping your contributions and connections intact. Username Uncertainties Unraveled Picking the perfect username is crucial--and sometimes the original choice you signed up with doesn't fit as well as you may have thought. There's a quick way to request an update here--but remember, your username is your community identity, so choose wisely. "Need Admin Approval" Warning Window? If you see this error message while using the community, don't worry. A simple process will help you get where you need to go. If you still need assistance, find out how to contact your Community Support team. Whatever you're looking for, when it comes to your profile, the Community Account Support Knowledge Base article is your treasure trove of tips as you navigate the nuances of your Community Profile. It’s the ultimate resource for keeping your digital identity in tip-top shape while engaging with the Power Platform Community. So, dive in and power up your profile today!  💪🚀   Community Account Support | Power Apps Community Account Support | Power AutomateCommunity Account Support | Copilot Studio  Community Account Support | Power Pages

Super User of the Month | Chris Piasecki

In our 2nd installment of this new ongoing feature in the Community, we're thrilled to announce that Chris Piasecki is our Super User of the Month for March 2024. If you've been in the Community for a while, we're sure you've seen a comment or marked one of Chris' helpful tips as a solution--he's been a Super User for SEVEN consecutive seasons!       Since authoring his first reply in April 2020 to his most recent achievement organizing the Canadian Power Platform Summit this month, Chris has helped countless Community members with his insights and expertise. In addition to being a Super User, Chris is also a User Group leader, Microsoft MVP, and a featured speaker at the Microsoft Power Platform Conference. His contributions to the new SUIT program, along with his joyous personality and willingness to jump in and help so many members has made Chris a fixture in the Power Platform Community.   When Chris isn't authoring solutions or organizing events, he's actively leading Piasecki Consulting, specializing in solution architecture, integration, DevOps, and more--helping clients discover how to strategize and implement Microsoft's technology platforms. We are grateful for Chris' insightful help in the Community and look forward to even more amazing milestones as he continues to assist so many with his great tips, solutions--always with a smile and a great sense of humor.You can find Chris in the Community and on LinkedIn. Thanks for being such a SUPER user, Chris! 💪🌠

Tuesday Tips: Community Ranks and YOU

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!This Week: Community Ranks--Moving from "Member" to "Community Champion"   Have you ever wondered how your fellow community members ascend the ranks within our community? What sets apart an Advocate from a Helper, or a Solution Sage from a Community Champion? In today’s #TuesdayTip, we’re unveiling the secrets and sharing tips to help YOU elevate your ranking—and why it matters to our vibrant communities. Community ranks serve as a window into a member’s role and activity. They celebrate your accomplishments and reveal whether someone has been actively contributing and assisting others. For instance, a Super User is someone who has been exceptionally helpful and engaged. Some ranks even come with special permissions, especially those related to community management. As you actively participate—whether by creating new topics, providing solutions, or earning kudos—your rank can climb. Each time you achieve a new rank, you’ll receive an email notification. Look out for the icon and rank name displayed next to your username—it’s a badge of honor! Fun fact: Your Community Engagement Team keeps an eye on these ranks, recognizing the most passionate and active community members. So shine brightly with valuable content, and you might just earn well-deserved recognition! Where can you see someone’s rank? When viewing a post, you’ll find a member’s rank to the left of their name.Click on a username to explore their profile, where their rank is prominently displayed. What about the ranks themselves? New members start as New Members, progressing to Regular Visitors, and then Frequent Visitors.Beyond that, we have a categorized system: Kudo Ranks: Earned through kudos (teal icons).Post Ranks: Based on your posts (purple icons).Solution Ranks: Reflecting your solutions (green icons).Combo Ranks: These orange icons combine kudos, solutions, and posts. The top ranks have unique names, making your journey even more exciting! So dive in, collect those kudos, share solutions, and let’s see how high you can rank! 🌟 🚀   Check out the Using the Community boards in each of the communities for more helpful information!  Power Apps, Power Automate, Copilot Studio & Power Pages

Find Out What Makes Super Users So Super

We know many of you visit the Power Platform Communities to ask questions and receive answers. But do you know that many of our best answers and solutions come from Community members who are super active, helping anyone who needs a little help getting unstuck with Business Applications products? We call these dedicated Community members Super Users because they are the real heroes in the Community, willing to jump in whenever they can to help! Maybe you've encountered them yourself and they've solved some of your biggest questions. Have you ever wondered, "Why?"We interviewed several of our Super Users to understand what drives them to help in the Community--and discover the difference it has made in their lives as well! Take a look in our gallery today: What Motivates a Super User? - Power Platform Community (microsoft.com)

Top Solution Authors
Top Kudoed Authors
Users online (6,103)