cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
OlaH
Helper III
Helper III

How to add a Pie Chart?

Easy visualization is important and I like to use pie charts that shows how products have been evaluated. But I need help, I can't find the documentation I need to understand how it works in Powerapps. Could you please help me of perhaps link to great guides?

 

My case:

In my app products are evaluated with sliders.

The sliders goes from 0 to 3 but I only show the values of 1-3. (0 = "No opinion" and 3 = Excellent)

 

How can I add pie charts that automaticly updates and shows how customer evaluates each product? 

 

Best regards

Ola

PieChart.png

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

You can add a "Filter" expression, and then group by the evaluation instead and you can count the number of customers that rated them that way.

Here is how I would do it:

 

 

	ClearCollect(YourData, 
	  {CustomerName: "Al", Product: "Hat", Evaluation: 1},	  {CustomerName: "Brad", Product: "Hat", Evaluation: 3},	  {CustomerName: "Carly", Product: "Jacket", Evaluation: 2},	  {CustomerName: "David", Product: "Shoes", Evaluation: 2},	  {CustomerName: "Edward", Product: "Hat", Evaluation: 2},	  {CustomerName: "Frederic", Product: "Hat", Evaluation: 1}
	);
ClearCollect(ChartData, Sort(AddColumns(GroupBy(Filter(YourData, Product = "Hat"), "Evaluation", "CustomerName"), "Total", CountRows(CustomerName)), Evaluation))

 

 Note that you could even add a DropDown for users to select which product, for example:

 

You can find an attached MSAPP that shows you how to do that.SampleApp.jpg

 

 

https://www.carlosag.net/downloads/ProductsApp.msapp

 

 

 

View solution in original post

4 REPLIES 4
carlosag
Power Apps
Power Apps

The Pie Chart control requires you to provide data that already calculates the numbers you would like to plot. In this case you would need to do a "group by" Product and perform the calculations on them and then provide that to the Pie Chart.

 

Here is an example on how you could add all the evaluations by product. Note that in this case I'm "hard-coding" a collection that attempts to match the schema you showed in your screenshot called "YourData" but really the only important line is the one creating the "ChartData" below.

ClearCollect(YourData, 
  {CustomerName: "Al", Product: "Hat", Evaluation: 1},
  {CustomerName: "Brad", Product: "Hat", Evaluation: 3},
  {CustomerName: "Carly", Product: "Jacket", Evaluation: 2},
  {CustomerName: "David", Product: "Shoes", Evaluation: 2},
  {CustomerName: "Edward", Product: "Hat", Evaluation: 2},
  {CustomerName: "Frederic", Product: "Hat", Evaluation: 1}
);
ClearCollect(ChartData, AddColumns(GroupBy(YourData, "Product", "CustomerName"), "Total", Sum(CustomerName, Evaluation)))

 

The only important line is where it GroupBy "Product" and then does a "Sum" of all the evaluations of the customers that rated that Product. You can then bind this to your Chart Items property and should work.

 

If instead you wanted the average evaluation for each product you can just switch to use the Average function,

 

ClearCollect(ChartData, AddColumns(GroupBy(YourData, "Product", "CustomerName"), "Total", Average(CustomerName, Evaluation)))

 

Or if you wanted to render the "count of customers" that rated each product, use CountRows:

 

ClearCollect(ChartData, AddColumns(GroupBy(YourData, "Product", "CustomerName"), "Total", CountRows(CustomerName)))

 

Hope this helps. To repro this, just copy the formula on the OnVisible of the first screen (you might need to add a new screen and navigate to it on the designer and come back so that the OnVisible is triggered to see the results), optionally you could add it to a "OnSelect" of a button that you can easily trigger.

 

Here is the average pie chart:

PieChart.jpg

Thank you so much @carlosag. Now I'm beginning to understand this. But how do I do if I want a pie chart for just "Hat"?

Look at my picture with the table and the pie chart. There are four evaluations of "Hat".

Two of them says "1" (blue in the pie chart) and then one each for "2" (green) and "3" (purple).

Acually, I don't care about the customername in this case. 

 

 

You can add a "Filter" expression, and then group by the evaluation instead and you can count the number of customers that rated them that way.

Here is how I would do it:

 

 

	ClearCollect(YourData, 
	  {CustomerName: "Al", Product: "Hat", Evaluation: 1},	  {CustomerName: "Brad", Product: "Hat", Evaluation: 3},	  {CustomerName: "Carly", Product: "Jacket", Evaluation: 2},	  {CustomerName: "David", Product: "Shoes", Evaluation: 2},	  {CustomerName: "Edward", Product: "Hat", Evaluation: 2},	  {CustomerName: "Frederic", Product: "Hat", Evaluation: 1}
	);
ClearCollect(ChartData, Sort(AddColumns(GroupBy(Filter(YourData, Product = "Hat"), "Evaluation", "CustomerName"), "Total", CountRows(CustomerName)), Evaluation))

 

 Note that you could even add a DropDown for users to select which product, for example:

 

You can find an attached MSAPP that shows you how to do that.SampleApp.jpg

 

 

https://www.carlosag.net/downloads/ProductsApp.msapp

 

 

 

View solution in original post

I love to learn!

Thank U @carlosag 4 helping me!

 

Ola

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (30,011)