Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Clustered column chart -percentage

Hi ,

 

How we can create a desired Chart  in power bi  from the below data:-

data in this chart will be dynamic , it will change according to filter of date & year.

sample chart.jpg

Data:--

YearWeekMonthSection-1StatusSection-2StatusSection-3StatusSection-4Status
2019Week 6Feb ICR ICR ICR ICR
2019Week 6Feb CR CR CR ICR
2019Week 6Feb ICR ICR ICR ICR
2019Week 7Feb CR CR ICR ICR
2019Week 7Feb ICR ICR ICR ICR
2019Week 7Feb CR ICR ICR ICR
2019Week 7Feb PD ICR PD ICR
2019Week 7Feb ICR ICR ICR ICR
2019Week 8Feb CR ICR CR ICR
2019Week 8Feb CR ICR CR CR
2019Week 8Feb CR ICR CR CR
2019Week 8Feb ICR ICR CR ICR
2019Week 8Feb ICR ICR CR ICR
2019Week 9Feb CR ICR CR CR
2019Week 9Feb PD PD CR PD
2019Week 9Feb ICR ICR CR PD
2019Week 9Feb CR CR CR PD
2019Week 9Feb PD PD CR PD
2019Week 9Feb ICR ICR ICR PD
2019Week 9Feb CR CR CR CR
2019Week 9Feb PD PD PD PD

 

 
 
  •  
1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @Anonymous and welcome aboard.

This looks like a question that can be solved with core visuals. As such, you will get a much faster response (probably within minutes) in a more frequented location like the Desktop forums for questions of this manner. They will also be able to give you better advice on how to do this using measures, as well and any specific formatting questions, but I'm confident that this will get you started.

Firstly, your data is not in quite the correct format as pasted. the Section-x columns are empty, and the status has its own separate column. If you can modify your source data a little bit then I would suggest that each status coumn has a Section-x heading and then we can transform it later. I'm going to assume that the structure can be changed to this:

YearWeekMonthSection 1Section 2Section 3Section 4
2019Week 6FebICRICRICRICR
2019Week 6FebCRCRCRICR
.....................

We'll use the query editor to make this fit your visual requirements. After import, we should have something like this:

Table after importTable after import

Now, select the first three columns, right-click and select Unpivot Other Columns from the context menu, e.g.:

Unpivot Other ColumnsUnpivot Other Columns

You'll now have a tall table, with and Attribute and a Value column, e.g.:

Table After UnpivotTable After Unpivot

You now have columns that will work as attributes in Power BI when you want to build your chart. We'll rename them to something more sensible for your use case (Section and Status), e.g.:

Renamed ColumnsRenamed Columns

Now, Close & Apply the query changes to be taken back to the Report view.

First, we'll put your filters in. Add two slicers to the canvas, and add Year to one and Week to the other, e.g.:

Slicers Added to CanvasSlicers Added to Canvas

You can add slicers for whatever fields you need - these two are just for illustrative purposes.

Now, add a Clustered Column Chart to the canvas.

  • Add the Section field from your data model to the Axis container on the chart.
  • Add Status to the Legend container.
  • Add Status to the Value container.

Our chart now looks like below. Note that the Status attribute changes to show Count of Status. This is because it's behaving as a measure for the chart. This doesn't quite fulfil your requirements, but we'll get to that in a second.

Clustered Column Chart with CountClustered Column Chart with Count

Power BI lets us convert this value to a % of grand total rather than the count, but this is for the whole visible data set, and it looks like you'll want to get this total for each Section value. We'll need a measure for this that takes this into consideration.

  • Right-click the table and select Add Measure
  • Paste the following DAX code into the text box:
    Section % = 
        DIVIDE(
            COUNT('Table1'[Status]),
            CALCULATE(
                COUNT(Table1[Status]),
                ALLSELECTED(Table1[Status])
            )
        )
    This will create a measure called Section %. This divides the value in each bar by the total for each section group. I would suggest that for more help on these kinds of areas, ask in the DAX forum, as there's some awesome people in there who can explain much better than I can 🙂

  • In the modelling ribbon, change your measure to a percentage format.
  • Replace the field in the Value container with this new measure, e.g.:
    Chart With %Chart With %

All that's left is your data labels:

  • Click on the Format pane, and switch Data Labels on.
  • Expand and change Value decimal places to 0.

And we're done!

Complete ChartComplete Chart

Selecting the slicers will modify the figures in the chart as needed, as per your requirements.

Hopefully this shows you what you need is possible.

Good luck!

Daniel

Did I answer your question? Mark my post as a solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

2 REPLIES 2
dm-p
Super User
Super User

Hi @Anonymous and welcome aboard.

This looks like a question that can be solved with core visuals. As such, you will get a much faster response (probably within minutes) in a more frequented location like the Desktop forums for questions of this manner. They will also be able to give you better advice on how to do this using measures, as well and any specific formatting questions, but I'm confident that this will get you started.

Firstly, your data is not in quite the correct format as pasted. the Section-x columns are empty, and the status has its own separate column. If you can modify your source data a little bit then I would suggest that each status coumn has a Section-x heading and then we can transform it later. I'm going to assume that the structure can be changed to this:

YearWeekMonthSection 1Section 2Section 3Section 4
2019Week 6FebICRICRICRICR
2019Week 6FebCRCRCRICR
.....................

We'll use the query editor to make this fit your visual requirements. After import, we should have something like this:

Table after importTable after import

Now, select the first three columns, right-click and select Unpivot Other Columns from the context menu, e.g.:

Unpivot Other ColumnsUnpivot Other Columns

You'll now have a tall table, with and Attribute and a Value column, e.g.:

Table After UnpivotTable After Unpivot

You now have columns that will work as attributes in Power BI when you want to build your chart. We'll rename them to something more sensible for your use case (Section and Status), e.g.:

Renamed ColumnsRenamed Columns

Now, Close & Apply the query changes to be taken back to the Report view.

First, we'll put your filters in. Add two slicers to the canvas, and add Year to one and Week to the other, e.g.:

Slicers Added to CanvasSlicers Added to Canvas

You can add slicers for whatever fields you need - these two are just for illustrative purposes.

Now, add a Clustered Column Chart to the canvas.

  • Add the Section field from your data model to the Axis container on the chart.
  • Add Status to the Legend container.
  • Add Status to the Value container.

Our chart now looks like below. Note that the Status attribute changes to show Count of Status. This is because it's behaving as a measure for the chart. This doesn't quite fulfil your requirements, but we'll get to that in a second.

Clustered Column Chart with CountClustered Column Chart with Count

Power BI lets us convert this value to a % of grand total rather than the count, but this is for the whole visible data set, and it looks like you'll want to get this total for each Section value. We'll need a measure for this that takes this into consideration.

  • Right-click the table and select Add Measure
  • Paste the following DAX code into the text box:
    Section % = 
        DIVIDE(
            COUNT('Table1'[Status]),
            CALCULATE(
                COUNT(Table1[Status]),
                ALLSELECTED(Table1[Status])
            )
        )
    This will create a measure called Section %. This divides the value in each bar by the total for each section group. I would suggest that for more help on these kinds of areas, ask in the DAX forum, as there's some awesome people in there who can explain much better than I can 🙂

  • In the modelling ribbon, change your measure to a percentage format.
  • Replace the field in the Value container with this new measure, e.g.:
    Chart With %Chart With %

All that's left is your data labels:

  • Click on the Format pane, and switch Data Labels on.
  • Expand and change Value decimal places to 0.

And we're done!

Complete ChartComplete Chart

Selecting the slicers will modify the figures in the chart as needed, as per your requirements.

Hopefully this shows you what you need is possible.

Good luck!

Daniel

Did I answer your question? Mark my post as a solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

Thanks for your support.

It works perfectly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors