Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
MiKeZZa
Post Patron
Post Patron

Create Pie chart with group by

Hi all,

 

I have a dataset like this:

 

emp nr  year_month uniquenumber
161860 201702         25005
161860 201702         25006 
161860 201703         25007 
365630 201702         25008 
365630 201703         25009 

 

And then I don't want to do some tricks in SQL, but in DAX to create a Pie Chart with 2 parts:

1 part with 3 (for emp nr 161860)

1 part with 2 (for emp nr 365630)

Is there anybody who can tell me how to fix this? I've been struggling with summarize and can't make it unfortionatelly.

 

16 REPLIES 16
MiKeZZa
Post Patron
Post Patron

Out of the box is even better.... 🙂

 

Both answers are not exactly what I'm looking for. To be more clear some extra data:

 

emp nr  year_month uniquenumber
161860 201702         25005
161860 201702         25006 
161860 201703         25007 
365630 201702         25008 
365630 201703         25009 

365631 201702         25010 
365631 201703         25011 

365632 201702         25012 
365632 201703         25013 

 

1 part with 3 (for emp nr 161860)

3 part's with 2 (for emp nr 365630, 365631 and 365632).

 

So I want 2 parts; 1 with 25% and value 3 and 1 with 75% and value 2. Tomorrow I'll check the link; maybe that explains everything...

Hi @MiKeZZa,

First, you should create a calculated column to get times each employee recorded using the formula.

times = CALCULATE(COUNTA(Test[emp nr]),ALLEXCEPT(Test,Test[emp nr]))


1.PNG

>>So I want 2 parts; 1 with 25% and value 3 and 1 with 75% and value 2. Tomorrow I'll check the link; maybe that explains everything...

Create a measure to calculted the percentage. 

Percent = CALCULATE(COUNTAX(DISTINCT(SELECTCOLUMNS(Test,"emp nr",Test[emp nr],"num",Test[times])),Test[Measure]),ALLEXCEPT(Test,Test[times]))/CALCULATE(COUNTAX(DISTINCT(SELECTCOLUMNS(Test,"emp nr",Test[emp nr],"num",Test[times])),Test[Measure]),ALL(Test))


Finally, create a pie chart, select the times as Legend level, the Percent as value level, please see the expected result in screenshot below.


2.PNG
Please let me know if you have any question.

Best Regards,
Angelia


Hi @v-huizhn-msft, thank you for this good tutorial. Problem is that I forget 1 part of the problem... I haven't been complete and my dataset is different now.... My complete dataset looks this way now:

 

emp nr  year_month numberoftimestocount costcentre
161860 201702         2                                    1234
161860 201703         1                                    1234
365630 201702         1                                    1234
365630 201703         0                                    1234

365630 201702         1                                    2345
365630 201703         0                                    2345

365631 201702         0                                    1234
365631 201703         1                                    1234

365632 201702         0                                    1234  
365632 201703         0                                    1234

 

Based on this dataset I want to see this:
161860 is 3 times sick in total dataset
365630 is 1 time sick in total dataset (despite of that the sum is 2, because of that it is the same month, but splitted into 2 records because of costcentre)

365631 is 1 time sick in total dataset
365632 is 0 times sick in total dataset

So my graph must then be:

2.png

 

Hi @MiKeZZa,

Plesae add another filter in times calculated columns. You will get correct result.

times = CALCULATE(SUM(Table3[number]),ALLEXCEPT(Table3,Table3[emp nr],Table3[costcentre]))


Then create measure like the solution above.

1.PNG

Best Regards,
Angelia

Hi @v-huizhn-msft thanks for you're patience.... But something goes wrong. I now have:

 

numberofcategories = CALCULATE(SUM('table name'[empnr]),ALLEXCEPT('table name','table name'[empnr],'table name'[costcenter]))

incidentcount = sum('table name'[numberofincidentsinmonth])

percentage = CALCULATE(COUNTAX(DISTINCT(SELECTCOLUMNS('table name',"empnr",'table name'[empnr],"num",'table name'[numberofcategories])),'table name'[incidentcount]),ALLEXCEPT('table name','table name'[numberofcategories]))/CALCULATE(COUNTAX(DISTINCT(SELECTCOLUMNS('table name',"empnr",'table name'[empnr],"num",'table name'[numberofcategories])),'table name'[incidentcount]),ALL('table name'))

And this results in this piechart:

piechart.png

 

I'm pretty sure I've done everything that you suggest, but it's clear that something is wrong.

Hi @MiKeZZa

In this chart, it seems that you post your table[emp nr ] as Lengend, please post table[numberofcategories] as lengend. And do you create measure your calculated column?

Best Regards,
Angelia

Hi Angelia,

 

I really don't understand you're questions. What do you mean with Lengend? And 'do you create measure your calculated column'?

 

Sorry, I'm really desperate for help, but don't understand what you're asking...

Hi @MiKeZZa

For pie visual, you select the "numberofcategories" field as Legend level, and Percent measure as value level?

 

Best Regards,
Angelia

No, still not good unfortionately....

 

If I select 1 person I have this dataset:

 

emp nr  year_month numberoftimestocount costcentre

161860 201606         0                                    1234

161860 201607         0                                    1234

161860 201608         0                                    1234

161860 201609         0                                    1234

161860 201610         0                                    1234

161860 201611         0                                    1234

161860 201612         0                                    1234

161860 201701         1                                    1234

161860 201702         0                                    1234
161860 201703         0                                    1234

 

This must result in 1 person that has 1 as count. So it must be a piechart with 100% score for group '1'. But what I get is this:

piechart.png

 

So it looks like he splits the data on the number of incidents, instead of summing them....

 

Can somebody PLEASE help me?

I've spent a few hours this weekend but it's really hard.... Anyone with more DAX skills than me?

Hi @MiKeZZa,

Could you please share your .pbix for further analysis?

Best Regards,
Angelia

Here is the (anonymised) pbix file: Download

 

It's (in my opinion) all about the fields used in the Pie Chart.

 

The filtered person has 2 incidents so I expect a pie with value 2 filled for 100%.

Anyone an idea?

I have tried it with the blog but I don't think it's what I need. I don't want to make my own groups, but I want to group on the outcome of the calculation. So it must become something like this:

 example.png

 

Sean
Community Champion
Community Champion


@MiKeZZa wrote:

 in DAX to create a Pie Chart with 2 parts:

1 part with 3 (for emp nr 161860)

1 part with 2 (for emp nr 365630)


 

I'm not sure - is this what you are after?

 

Pie Chart.png

Seth_C_Bauer
Community Champion
Community Champion

@MiKeZZa Not a direct solution as you are requesting DAX, but you can do this with Out of the Box functionality in Power BI without DAX.

Check out this blog

Just threw this together off your request. 2 minutes.pie.PNG

 

 


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.