Forum Discussion
Formatting a bar graph
Hello all,
I have this sample data in Power BI:
| Users | Salesmembers | Managers | Cars | Phones | Expenses | pagers |
| 10,205 | 1,500 | 500 | 2,000 | 2,000 | 1,503 | 1,500 |
and I am trying to create a chart like this:
how can I recreate this in power bi? specifically with the category labels under the bars
thank you!!
If that is how your source data is actually formatted, you need to unpivot all of those columns in Power Query and then the solution is trivial. Otherwise, create a disconnected table that lists your columns (categories). Use this as the Axis for your chart. Then create a measure that uses a SWITCH statement and based on the value in the axis, sum the right column as the return value for the measure.
7 Replies
- Greg_DecklerCommunity Champion
If that is how your source data is actually formatted, you need to unpivot all of those columns in Power Query and then the solution is trivial. Otherwise, create a disconnected table that lists your columns (categories). Use this as the Axis for your chart. Then create a measure that uses a SWITCH statement and based on the value in the axis, sum the right column as the return value for the measure.
- AnonymousNot applicable
can I unpivot using dax? I dont want to mess up all my other visuals
- Greg_DecklerCommunity Champion
As a matter of fact, yes you can. I wrote a quick measure to do exactly that. https://community.powerbi.com/t5/Quick-Measures-Gallery/DAX-Unpivot/m-p/574832#M256.
However, that will not solve your problem since you still need something to put in the Axis. Sounds like you are headed down the disconnected table trick, this blog article demonstrates the technique. https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick/ba-p/279563
- AnonymousNot applicable
do you have a quick example of the switch statment to use in this case? I just created the table of all the categories for the axis
- danextianSuper User
Hi Anonymous ,
With the data you've posted, here's one way of you can achieve your desired result:
- Go the Query Editor and select all those columns.
- Then right click and hit Unpivot Columns.
- Unpivot will create two columns: Attribute and Value. Change Attribute to data type text and Value to Number.
- Apply the changes.
- Insert a bar chart. Add Attribute to Axis and Value to Value (make sure that the aggregation is sum).
- AnonymousNot applicable
is it possible to do the unpivot with DAX?