Forum Discussion

iamblue91's avatar
iamblue91
Frequent Visitor
9 years ago
Solved

Another 100% Stacked Bar Chart Question

Hi all!  Really beginner question, so I apologize.    I'm trying to sort Task Type as a share of % of an employee's total time for the month. The current issue is in the image attached -- each p...
  • dearwatson's avatar
    9 years ago

    Hi iamblue,

     

    Welcome to the revolution :)

     

    there are ways to do this without DAX but if you want to use PowerBI in any meaningful way you'll need DAX... and this is a good one to get started on:

     

    First we make an easy measure: SUM of Hours (in this case the column Table1[Hours]) - this is already being done for you automatically in your graph but we create an "Explicit Measure" because we should NEVER use implicit measures according to the gurus of DAX.

     

    create a measure:

    Total Hours = SUM(Table1[Hours])

     

    Now we use DAX magic to give us a measure that will always return the TOTAL hours even if we filter it...

    We'll call it a Grand Total.

    Grand Total Hours = CALCULATE([Total Hours],ALL(Table1)) -- this uses CALCULATE to remove the filters with the ALL function.

     

    so the percentage calculation is:

    Perc of Total Hours = DIVIDE([Total Hours], [Grand Total Hours],0)

     

    Add the "perc of Total Hours Measure" as the Value in the 100% stack. Person Name in Axis, Activity in Legend... DONE.

     

    Now that you learned the DAX way here's the 2 second no DAX solution:

    =============================

    Create blank 100% stacked bar graph

    drag Hours to Value (<-- this defaults to an Implicit SUM so you really should create a measure)

    drag Name to Axis

    drag Activity to Legend

    In the Visualizations pane click the little down arrow next to "Hours"

    select Quick Calc->Show Value as Percent of Grand Total

     

    Viola!

     

     

    That should do it...