Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
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 1 | Class 2 |
0 | 1 |
1 | 1 |
1 | 1 |
0 | 1 |
1 | 0 |
I would like to receive the following bar chart:
How can I implement this in Power BI? Thanks a lot for your help!
Solved! Go to Solution.
You need to transform your table in Power Query:
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 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
You need to transform your table in Power Query:
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 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Your reply was great, it helped me a lot. Thank you!
I had problems to upload the diagramm, so I try it again...
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
29 | |
12 | |
12 | |
11 | |
8 |
User | Count |
---|---|
53 | |
28 | |
15 | |
14 | |
13 |