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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
ZME4
Regular Visitor

Bar chart in Power BI

Hello together,

 

I have a question. I would like to draw a bar chart in Power BI which counts the values of the same type for two classes.

The table looks like this:

Class 1Class 2
01
11
11
01
10

 

I would like to receive the following bar chart:

 

 

How can I implement this in Power BI? Thanks a lot for your help!

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@ZME4 

 

You need to transform your table in Power Query:

 

Fowmy_0-1604588906839.png

Go to Power Query > Get Data > Blank Query > go to Advanced Editor in View Menu, Clear all that is there and paste the below code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTJUitWJBpKYLFRZA6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Class 1" = _t, #"Class 2" = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Index",{{"Class 1", Int64.Type}, {"Class 2", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Index"}, "Attribute", "Value"),
    #"Duplicated Column" = Table.DuplicateColumn(#"Unpivoted Other Columns", "Value", "Value - Copy"),
    #"Removed Columns" = Table.RemoveColumns(#"Duplicated Column",{"Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "Legend"}, {"Attribute", "Class"}, {"Value - Copy", "Value"}})
in
    #"Renamed Columns"

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@ZME4 

 

You need to transform your table in Power Query:

 

Fowmy_0-1604588906839.png

Go to Power Query > Get Data > Blank Query > go to Advanced Editor in View Menu, Clear all that is there and paste the below code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTJUitWJBpKYLFRZA6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Class 1" = _t, #"Class 2" = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Index",{{"Class 1", Int64.Type}, {"Class 2", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Index"}, "Attribute", "Value"),
    #"Duplicated Column" = Table.DuplicateColumn(#"Unpivoted Other Columns", "Value", "Value - Copy"),
    #"Removed Columns" = Table.RemoveColumns(#"Duplicated Column",{"Index"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "Legend"}, {"Attribute", "Class"}, {"Value - Copy", "Value"}})
in
    #"Renamed Columns"

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

ZME4
Regular Visitor

Your reply was great, it helped me a lot. Thank you!

ZME4
Regular Visitor

I had problems to upload the diagramm, so I try it again...BarChartTwoClasses.png

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors