Forum Discussion

kodnil2020's avatar
kodnil2020
Icon for Helper I rankHelper I
6 years ago
Solved

Create Clustered column Chart

Hello, 

 

I am new to Power BI and still needs to learn few things. Appreciate your help here. 

I have 2 tables:

Table 1:  Employee Grades with Department

Table 2:  Active/Inactive employees

 

Ask: Create Clustered coumn chart of Active employees

 

D & Above  75%
C  25%
B 66.66% 
A100%33.33% 
 Dept1Dept2Dept3

 

Sample Data:

Table 1: 

DepartmentGradeID
Dept1A111
Dept1A212
Dept2A113
Dept2B114
Dept2B215
Dept3C116
Dept3D117
Dept3D218
Dept3E119
Dept3C120
Dept2D121

 

Table 2:  

IDActive
111
121
131
141
151
161
171
181
191
200
210
  • Hi kodnil2020 ,

     

    We can create a column and a matrix table to meet your requirement.

     

    1. Create a calculate column to sort Grade.

     

    Legend = 
    SWITCH(
        TRUE(),
        CONTAINSSTRING('Table 1'[Grade],"A"),"A",
        CONTAINSSTRING('Table 1'[Grade],"B"),"B",
        CONTAINSSTRING('Table 1'[Grade],"C"),"C","D & Above")

     

     

    Then we can create a measure and put the column to legend in Clustered Column Chart.

     

    Measure = 
    var _x = CALCULATE(DISTINCTCOUNT('Table 1'[ID]),FILTER('Table 2','Table 2'[Active]=1))
    var _y = CALCULATE(DISTINCTCOUNT('Table 1'[ID]),FILTER(ALLSELECTED('Table 2'),'Table 2'[Active]=1),FILTER(ALLSELECTED('Table 1'),'Table 1'[Department]=MAX('Table 1'[Department])))
    return
    DIVIDE(_x,_y)

     

     

    If you have any question, please kindly ask here and we will try to resolve it.

     

    Best regards,

     

    Community Support Team _ zhenbw

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

     

    BTW, pbix as attached.

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    kodnil2020 - Assuming that your tables are related on ID, you should just have to add Active column to your Filters pane and set it to 1.

     

    And, welcome to the community. Check out this article here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

     

    And you did really well on that front! 🙂

  • v-zhenbw-msft's avatar
    v-zhenbw-msft
    Icon for Community Support rankCommunity Support

    Hi kodnil2020 ,

     

    We can use the following steps to meet your requirement.

     

    1. We assume that the two tables have a relationship based on [ID].

     

     

    2. Then we can create a measure.

     

    active person count = CALCULATE(DISTINCTCOUNT('Table 2'[ID]),FILTER('Table 2','Table 2'[Active]=1))

     

    Or this measure is also right.

     

    active sum = CALCULATE(SUM('Table 2'[Active]))

     

     

    If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

     

    Best regards,

     

    Community Support Team _ zhenbw

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

     

    BTW, pbix as attached.

    • kodnil2020's avatar
      kodnil2020
      Icon for Helper I rankHelper I

      Yes. 2 tables are connected.

      This is what i am looking for:

      For all departments show clustered chart:

      1. X axis: departments

      2. Y Axis: percentage of Active Grades

       

      Group all "A" grades and find percentage based on active employees

      Group all "B" grades and find percentage based on active employees

      Group all "C" grades and find percentage based on active employees 

      Group all "D & Above" grades and find percentage based on active employees

       

      Sample graph & percentage calculation below:

       
       
       
       

       

      • v-zhenbw-msft's avatar
        v-zhenbw-msft
        Icon for Community Support rankCommunity Support

        Hi kodnil2020 ,

         

        We can create a column and a matrix table to meet your requirement.

         

        1. Create a calculate column to sort Grade.

         

        Legend = 
        SWITCH(
            TRUE(),
            CONTAINSSTRING('Table 1'[Grade],"A"),"A",
            CONTAINSSTRING('Table 1'[Grade],"B"),"B",
            CONTAINSSTRING('Table 1'[Grade],"C"),"C","D & Above")

         

         

        Then we can create a measure and put the column to legend in Clustered Column Chart.

         

        Measure = 
        var _x = CALCULATE(DISTINCTCOUNT('Table 1'[ID]),FILTER('Table 2','Table 2'[Active]=1))
        var _y = CALCULATE(DISTINCTCOUNT('Table 1'[ID]),FILTER(ALLSELECTED('Table 2'),'Table 2'[Active]=1),FILTER(ALLSELECTED('Table 1'),'Table 1'[Department]=MAX('Table 1'[Department])))
        return
        DIVIDE(_x,_y)

         

         

        If you have any question, please kindly ask here and we will try to resolve it.

         

        Best regards,

         

        Community Support Team _ zhenbw

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

         

        BTW, pbix as attached.