Forum Discussion

majid154a's avatar
majid154a
Helper II
2 years ago
Solved

Dealing with percents

I have data containing the following columns: Category, Sub-Category, Order ID, and Country.

I want to visualize this data using a Matrix chart such that:
- Category and Sub-Category are in the Rows.
- Country is in the Columns.
- The values represent the Order Count.

Requirements:
1. How can I make the order percentages for each Category add up to 100%?
2. When performing a Drill Down on a specific Category to show the Sub-Categories, how can I ensure that the sum of all Sub-Categories equals 100%?
3. How can I ensure that the total percentages in the columns and rows add up to 100%?

What is the method to achieve this in Power BI?

see here convert numbers to percent:

 

 

Attaced data as example: 

Order IDCategorySub-CategoryCountry
1FurnitureChairsUnited States
2OfficePaperUnited States
3TechnologyPhonesUnited States
4FurnitureTablesUnited States
5OfficeBindersUnited States
6TechnologyLaptopsUnited States
7FurnitureBookcasesUnited States
8OfficeArtUnited States
9TechnologyAccessoriesUnited States
10FurnitureFurnishingsUnited States
11OfficeLabelsUnited States
12TechnologyCopiersUnited States
13FurnitureChairsUnited States
14OfficeEnvelopesUnited States
15TechnologyPhonesUnited States
16FurnitureTablesUnited States
17OfficeStorageUnited States
18TechnologyLaptopsUnited States
19FurnitureBookcasesDenmark
20OfficeSuppliesDenmark
21TechnologyAccessoriesDenmark
22FurnitureFurnishingsDenmark
23OfficePaperDenmark
24TechnologyCopiersDenmark
25FurnitureChairsDenmark
26OfficeArtDenmark
27TechnologyPhonesDenmark
28FurnitureTablesDenmark
29OfficeBindersDenmark
30TechnologyLaptopsDenmark
31FurnitureBookcasesDenmark
32OfficeLabelsDenmark
33TechnologyAccessoriesDenmark
34FurnitureFurnishingsDenmark
35OfficeEnvelopesDenmark
36TechnologyCopiersVietnam
37FurnitureChairsVietnam
38OfficeStorageVietnam
39TechnologyPhonesVietnam
40FurnitureTablesVietnam
41OfficeSuppliesVietnam
42TechnologyLaptopsVietnam
43FurnitureBookcasesVietnam
44OfficePaperVietnam
45TechnologyAccessoriesVietnam
46FurnitureFurnishingsVietnam
47OfficeArtVietnam
48TechnologyCopiersVietnam
49FurnitureChairsVietnam
50OfficeBindersVietnam
51TechnologyPhonesVietnam
52FurnitureTablesVietnam
53OfficeLabelsVietnam
54TechnologyLaptopsVietnam
55FurnitureBookcasesVietnam
56OfficeEnvelopesVietnam
57TechnologyAccessoriesVietnam
58FurnitureFurnishingsVietnam
59OfficeStorageVietnam
60TechnologyCopiersVietnam
61FurnitureChairsVietnam
62OfficePaperVietnam
63TechnologyPhonesVietnam
64FurnitureTablesVietnam
65OfficeBindersVietnam
66TechnologyLaptopsVietnam
67FurnitureBookcasesVietnam
68OfficeArtVietnam
69TechnologyAccessoriesVietnam
70FurnitureFurnishingsVietnam
71OfficeLabelsVietnam
72TechnologyCopiersVietnam
73FurnitureChairsVietnam
74OfficeEnvelopesVietnam
75TechnologyPhonesVietnam
76FurnitureTablesVietnam
77OfficeStorageVietnam
78TechnologyLaptopsVietnam
79FurnitureBookcasesVietnam
80OfficeSuppliesVietnam
81TechnologyAccessoriesVietnam
82FurnitureFurnishingsVietnam
83OfficePaperKosovo
84TechnologyCopiersKosovo
85FurnitureChairsKosovo
86OfficeArtKosovo
87TechnologyPhonesKosovo
88FurnitureTablesKosovo
89OfficeBindersKosovo
90TechnologyLaptopsKosovo
91FurnitureBookcasesKosovo
92OfficeLabelsKosovo
93TechnologyAccessoriesKosovo
94FurnitureFurnishingsKosovo
95OfficeEnvelopesKosovo
96TechnologyCopiersKosovo
97FurnitureChairsKosovo
98OfficeStorageKosovo
99TechnologyPhonesKosovo
100FurnitureTablesKosovo
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi majid154a ,

     

    Modify measure.

    MEASURE = 
    VAR _count =
        COUNT ( 'Table'[Order ID] )
    VAR _all =
        CALCULATE ( COUNT ( 'Table'[Order ID] ), ALLSELECTED ( 'Table'[Sub-Category]) )
    RETURN
        DIVIDE ( _count, _all )
    

     

    If your Current Period does not refer to this, please clarify in a follow-up reply.

     

    Best Regards,

    Clara Gong

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • Percentages in Power BI are achieved obviously with the division of a numerator by a denominator.

     

    The DIVIDE function is key, but the harder part (as least as i've been learning) in Power BI is understanding a concept called filter context - basically how the tables are populated. For the denominator to work correctly as you want you'll need to remove filters being applied to the numerator. Which filters depend on what you want to divide by. This will be acheived using the REMOVEFILTERS function.

     

    This will likley involve removing the filters that apply to country (to give a total of all the orders across countries) and removing the filters on subcategory. To get each one to add up to 100%, probably need to use two different measures.

     

    Here's a really helpful video explaining filter context from the nice people as SQLBI:

    https://www.youtube.com/watch?v=L5WR-imfyYI 

     

    Hope that helps point you in the right direction.

     

    Adam

  • Anonymous's avatar
    Anonymous
    Not applicable

    Source Data

    Sub Category order id count formula

    Count % formula

    Matrix visual elements

     



  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi majid154a ,

     

    Thanks for the reply from Anonymous  and BINewbie1 , please allow me to provide another insight:

     

    You can try this measure expression.

    MEASURE = 
    VAR _count =
        COUNT ( 'Table'[Order ID] )
    VAR _all =
        CALCULATE ( COUNT ( 'Table'[Order ID] ), ALLSELECTED ( 'Table' ) )
    RETURN
        DIVIDE ( _count, _all )
    

     

     

    If your Current Period does not refer to this, please clarify in a follow-up reply.

     

    Best Regards,

    Clara Gong

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • majid154a's avatar
      majid154a
      Helper II

      Thank you for helping Anonymous 

      In the image below, I need the red circle to represent 100%. Additionally, I need each yellow circle to also represent 100%.

      How can we achieve this?

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi majid154a ,

         

        Modify measure.

        MEASURE = 
        VAR _count =
            COUNT ( 'Table'[Order ID] )
        VAR _all =
            CALCULATE ( COUNT ( 'Table'[Order ID] ), ALLSELECTED ( 'Table'[Sub-Category]) )
        RETURN
            DIVIDE ( _count, _all )
        

         

        If your Current Period does not refer to this, please clarify in a follow-up reply.

         

        Best Regards,

        Clara Gong

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.