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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
HassanAshas
Helper V
Helper V

How to change between pie-charts with the change in user selection

I have a dataset like this, 

 

Emp CodeNameCompetencyPractice
1MattDataAI
2AveryDataAI
3AryubDataAnalytics
4JacobCloudAWS
5ZaraDataEngineering
6AliCloudDevOps
7JohnCloudDevOps
8AlishaMarketingServices
9NovakMarketingAdvertisement
10AlexHRHRBP
11EmmaHRRecruitment

 

I have one slicer which allows the user to select between different competencies. I also have a pie-chart that displays Total Employees per Competency., as shown in the following image, 

 

HassanAshas_0-1677910240409.png

What I need is, 

 

  • If the user has not selected any competency, Pie-chart should display Total Employees per Competency
  • If the user has selected any competency, Pie-chart should display Total Employees per Practice 

Is it possible to do in the Power BI? 

 

One solution I know of is to use buttons and bookmarks to navigate between different bookmarks, with each bookmark having a pie-chart against each competency selection. But I can't use this approach because of two reasons, 1) I can't place Buttons in a drop down slicer, which is a requirement for me. 2) Bookmarks can't be dynamic (so for example, if a new Competency comes in the data later on, that wil not be added automatically) 

 

Can anyone help in this? Thanks

 

If you would like to download the Example Power BI Workbook, you may do so here: https://drive.google.com/file/d/1DnTGDlaiTqL5GsuAw6DHko0GqHCS3d3h/view?usp=sharing

2 ACCEPTED SOLUTIONS
barritown
Super User
Super User

Hi @HassanAshas

Probably an easier and more elegant solution exists, but that's not my way so I found the one that follows below.

 

Step 1.
We create 2 additional tables.

 

barritown_0-1678047457337.png

barritown_1-1678047494229.png

 

The first one ('Slicer Table') will be used in a slicer, the second one ('Augmented data') will be our working table from now on.


Step 2.
We create a link between them.

 

barritown_2-1678047631808.png


Step 3.
We add a slicer and filter out BLANK in it.

 

barritown_3-1678047724393.png


Step 4.
We create a measure like this...

 

barritown_4-1678047821574.png


...and add it to the Values field of our Pie Chart where the Legend field is populated with 'Augmented data' [Shown].

 

barritown_5-1678047896904.png

 

And it works:

 

barritown_6-1678047950437.png

barritown_7-1678048003774.png


Here's the file with my experiments - https://www.dropbox.com/s/x3svyohot0ympza/Pie%20Chart%20-%202%20Columns.pbix?dl=0

 

Let me know if it works for you or should you need some additional clarifications.

View solution in original post

@HassanAshas 

Hi again,

The idea that there must be a more elegant solution to your problem (comparing to x2 of the fact table) was preying on my mind for some time. Then I gave up, but recently, while solving another problem, I've come up with another solution. I am not quite sure that it will work perfectly with big data - up to you to try.

 

The 1st step is to create a table with the unique values from the columns [Competency] and [Practice]:

Content = 
UNION (
    SELECTCOLUMNS ( VALUES ( Data[Competency] ), "Value", [Competency] ),
    SELECTCOLUMNS ( VALUES ( Data[Practice] ), "Value", [Practice] ) )

 

The 2nd step is to create a measure:

CountOfItems = 
VAR CurrentValue = MIN ( 'Content'[Value] )
RETURN IF ( ISFILTERED ( Data[Competency] ), 
            COUNTX ( FILTER ( Data, Data[Practice] = CurrentValue ), [Name] ),
            COUNTX ( FILTER ( Data, Data[Competency] = CurrentValue ), [Name] ) )

 

The 3rd, and the final, step is to add those newly created items to the pie chart and enjoy the result:

barritown_0-1686471750002.pngbarritown_1-1686471783524.png

Here's my updated PBIX - https://www.dropbox.com/s/tvkvgide1g07fax/Pie%20Chart%20-%202%20Columns%20-%20v2.pbix?dl=0

Cheers!

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

3 REPLIES 3
barritown
Super User
Super User

Hi @HassanAshas

Probably an easier and more elegant solution exists, but that's not my way so I found the one that follows below.

 

Step 1.
We create 2 additional tables.

 

barritown_0-1678047457337.png

barritown_1-1678047494229.png

 

The first one ('Slicer Table') will be used in a slicer, the second one ('Augmented data') will be our working table from now on.


Step 2.
We create a link between them.

 

barritown_2-1678047631808.png


Step 3.
We add a slicer and filter out BLANK in it.

 

barritown_3-1678047724393.png


Step 4.
We create a measure like this...

 

barritown_4-1678047821574.png


...and add it to the Values field of our Pie Chart where the Legend field is populated with 'Augmented data' [Shown].

 

barritown_5-1678047896904.png

 

And it works:

 

barritown_6-1678047950437.png

barritown_7-1678048003774.png


Here's the file with my experiments - https://www.dropbox.com/s/x3svyohot0ympza/Pie%20Chart%20-%202%20Columns.pbix?dl=0

 

Let me know if it works for you or should you need some additional clarifications.

Haha, this definitely works but surely not something I can try with a much larger dataset (which is what's the case for me :P) 

It would be very troublesome to duplicate the whole of fact table xD, and I wonder whether it will work for three or four levels? Thinking about it. (In my original problem, I don't have only "Competency" and "Practice". I have two levels above it too and one level below as well 😛 so basically its like Company -> Competency -> Practice -> Sub-Practices) 

 

But honestly, I have tried all I could and only found that it is not possible to implement this (as of now at least).

I greatly appreciate you responding and putting so much time in trying to solve this, by the way. Thank you so much! This is the closest solution we can get to this problem, perhaps. 

@HassanAshas 

Hi again,

The idea that there must be a more elegant solution to your problem (comparing to x2 of the fact table) was preying on my mind for some time. Then I gave up, but recently, while solving another problem, I've come up with another solution. I am not quite sure that it will work perfectly with big data - up to you to try.

 

The 1st step is to create a table with the unique values from the columns [Competency] and [Practice]:

Content = 
UNION (
    SELECTCOLUMNS ( VALUES ( Data[Competency] ), "Value", [Competency] ),
    SELECTCOLUMNS ( VALUES ( Data[Practice] ), "Value", [Practice] ) )

 

The 2nd step is to create a measure:

CountOfItems = 
VAR CurrentValue = MIN ( 'Content'[Value] )
RETURN IF ( ISFILTERED ( Data[Competency] ), 
            COUNTX ( FILTER ( Data, Data[Practice] = CurrentValue ), [Name] ),
            COUNTX ( FILTER ( Data, Data[Competency] = CurrentValue ), [Name] ) )

 

The 3rd, and the final, step is to add those newly created items to the pie chart and enjoy the result:

barritown_0-1686471750002.pngbarritown_1-1686471783524.png

Here's my updated PBIX - https://www.dropbox.com/s/tvkvgide1g07fax/Pie%20Chart%20-%202%20Columns%20-%20v2.pbix?dl=0

Cheers!

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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