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

@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.

@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

 

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

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,075)