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

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
Super User
Super User

Re: Populate a gallery with summarised data from a collection?

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Populate a gallery with summarised data from a collection?

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.

Super User
Super User

Re: Populate a gallery with summarised data from a collection?

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Community Support Team
Community Support Team

Re: Populate a gallery with summarised data from a collection?

Hi @MarkSL 

 

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

If it works ,please accept it as solution.

 

Best Regards.

Yumia

MarkSL
Level: Powered On

Re: Populate a gallery with summarised data from a collection?

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
Level: Powered On

Re: Populate a gallery with summarised data from a collection?

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

Highlighted
Super User
Super User

Re: Populate a gallery with summarised data from a collection?

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,840)