Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in BI by (11.1k points)

How can I create a pie chart in power bi and want to display the percent of selected items like

---------------------------
| Id | Product | Category |
| 1  |   P1    |    A     |
| 2  |   P2    |    A     |
| 3  |   P3    |    A     |
| 4  |   P4    |    B     |
| 5  |   P5    |    B     |
| 6  |   P6    |    B     |
| 7  |   P7    |    C     |
| 8  |   P8    |    C     |
| 9  |   P9    |    D     |
---------------------------

I had a measure 

Count not Selected Products =
CALCULATE (
    COUNT ( Products[Product] ),
    FILTER (
        ALL ( Products[Category] ),
        NOT Products[Category] IN VALUES ( Products[Category] )
    ) 

) 

Count Selected =
CALCULATE (
    COUNT ( Products[ID] ),
    FILTER ( Products, Products[Category] IN ALLSELECTED ( Products[Category] ) ) 

) 

enter image description here

How can i do this? 

1 Answer

0 votes
by (22.5k points)
edited by

Use the following measures

Pie = UNION ( VALUES ( Products[Category] ), { { "Remaining" } } )

Shows a single-column table

 Category

--------
A
B
C
D
Remaining

and use this measure

CountProducts =
IF (
    SELECTEDVALUE ( Pie[Category] ) = "Remaining",
    CALCULATE (
        COUNT ( Products[Product] ),
        ALL ( Products[Category] ),
        NOT ( Products[Category] IN VALUES ( Products[Category] ) )
    ),
    CALCULATE (
        COUNT ( Products[Product] ),
        FILTER ( Products, Products[Category] IN VALUES ( Pie[Category] ) )
    ) 

) 

Pie Chart

To get the result in such a way 

Want to learn more about Power Bi, CheckOut: power bi tutorial  

We also provide Power BI Online Course, Enroll now!

Related questions

0 votes
1 answer
asked Dec 12, 2020 in BI by Chris (11.1k points)
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...