Forum Discussion

jgiles's avatar
jgiles
Frequent Visitor
4 years ago
Solved

Percentage in clustered column chart visual

Hi,
I have a clustered column chart visual and the percentage is calculating across the grand total.   I'm trying to create a measure or column to calculate the level % by year.  Example Level A is 25%, B, 25%, C 40% and D 10% for YEAR 2020. I also provided a table below of what I'd want the percentage to be on the graph.  Also, a sample table of the data is below.  

  

 

 

Correct Percentage to display 
Level202020212022
A12.08%41.33%18.75%
B66.44%48.44%0.00%
C10.74%10.22%31.25%
D10.74%0.00%50.00%
 100.00%100.00%100.00%



Sample table:

YEARLevelCount
2021B109
2020B99
2021A93
2021C23
2020A18
2020C16
2020D16
2022D8
2022C5
2022A3


Thank you,

Julie

  • jgiles  I started working on this before HotChilli  replied and then got interrupted. Am coming back to it now, so to expand on what HotChilli  said, here's exactly how you can clear the filter on Level.

     

    You've selected the % of GT - which clears filters on Level AND Year. You only want a subtotal, so only want to clear the filter on Level. Using the ALL function in DAX in combo with CALCULATE we can do this: 

     

    % of all Levels Count =
    DIVIDE(SUM(LevelsSample[Count]), CALCULATE(SUM(LevelsSample[Count]), ALL(LevelsSample[Level])))

     

    '

     

    Sample file attached below signature. Thanks jgiles  for the easy to copy/paste sample data - you made it very easy to answer your question. 🙂 

     

     

  • jgiles  That's an interesting one I haven't noticed, but it makes sense if my guess is right: My guess is that the column level is sorting by is actually applying the filter too, so you need to add 

    ALL(Table[LevelSortColumn]) 

    as a filter argument too and that should do the trick. 

8 Replies

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

    The value on the chart is a measure that represents SUM(SampleTable[Count]),

    so you need to write a measure that takes this value and divides it by the same measure which has the Level filters removed.

    Is that enough to get you started?

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

    jgiles  I started working on this before HotChilli  replied and then got interrupted. Am coming back to it now, so to expand on what HotChilli  said, here's exactly how you can clear the filter on Level.

     

    You've selected the % of GT - which clears filters on Level AND Year. You only want a subtotal, so only want to clear the filter on Level. Using the ALL function in DAX in combo with CALCULATE we can do this: 

     

    % of all Levels Count =
    DIVIDE(SUM(LevelsSample[Count]), CALCULATE(SUM(LevelsSample[Count]), ALL(LevelsSample[Level])))

     

    '

     

    Sample file attached below signature. Thanks jgiles  for the easy to copy/paste sample data - you made it very easy to answer your question. 🙂 

     

     

    • jgiles's avatar
      jgiles
      Frequent Visitor

      AllisonKennedy One more question.  Why wouldn't this work if the Level was sorted by a different column?  I'm getting 100% but if I change the sort order of Level back to just Level it works.  Thank you!

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

        jgiles  That's an interesting one I haven't noticed, but it makes sense if my guess is right: My guess is that the column level is sorting by is actually applying the filter too, so you need to add 

        ALL(Table[LevelSortColumn]) 

        as a filter argument too and that should do the trick. 

    • pipkinp86's avatar
      pipkinp86
      Regular Visitor

      Thank you very much, I wish I had seen this before, I used to break my data in separated tables to get the same result.